From 9deacd7f2080cc042430df0fe615ed84ee493390 Mon Sep 17 00:00:00 2001 From: Martin Klapetek Date: Tue, 3 Sep 2013 10:29:42 +0200 Subject: [PATCH] Normalise and deduplicate paths for XDG_DATA_DIRS This removes the trailing slashes from the path and then removes dirs set twice in XDG_DATA_DIRS (always removes those from the right side). There's no use for duplicit dirs in XDG_DATA_DIRS because if whatever is being looked up is not found in the duplicated dir the first time, it won't be there the second time. Currently it causes troubles for example in mime types, where it returns duplicated mime types as the same dir is searched multiple times. For obtaining the original value of XDG_DATA_DIRS, one can use qgetenv("XDG_DATA_DIRS"). Change-Id: Ic4f8ef6c6fe096555948e318899207e9d4ca8289 Reviewed-by: David Faure KDE (deprecated, use kdab instead) --- src/corelib/io/qstandardpaths_unix.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 1c9fa278cd2..61e2e03a3d2 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -257,6 +257,17 @@ static QStringList xdgDataDirs() dirs.append(QString::fromLatin1("/usr/share")); } else { dirs = xdgDataDirsEnv.split(QLatin1Char(':')); + // Normalize paths + for (int i = 0; i < dirs.count(); i++) + dirs[i] = QDir::cleanPath(dirs.at(i)); + + // Remove duplicates from the list, there's no use for duplicated + // paths in XDG_DATA_DIRS - if it's not found in the given + // directory the first time, it won't be there the second time. + // Plus duplicate paths causes problems for example for mimetypes, + // where duplicate paths here lead to duplicated mime types returned + // for a file, eg "text/plain,text/plain" instead of "text/plain" + dirs.removeDuplicates(); } return dirs; }