diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-01-29 21:04:52 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-07 20:24:02 +0000 |
commit | be51d1fda3ffcdbaddbff44a7cf1755bdb4f7f81 (patch) | |
tree | 962c406dade47fde2dd9259541f5a0dd7d39e92d /src | |
parent | 27fa5bfef4d2b36109342a3f1e01161d207041d1 (diff) | |
download | qtbase-be51d1fda3ffcdbaddbff44a7cf1755bdb4f7f81.tar.gz |
QStandardPaths/Unix: minor cleanup
- Better readability by returning early
- Make a QRegularExpression static const so that the regex pattern is
compiled only once
Change-Id: Ic0d6bd4b068624c4ff60c6e71d09f20393adaa64
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit 482a75fef9643220366029862dbf636a88bccb82)
Reviewed-by: Daniel Smith <Daniel.Smith@qt.io>
(cherry picked from commit f4eacea72bd1e248faa40d15a77c8f49a6b4d81f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 339f3c565e..038cdd3b8d 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -180,10 +180,11 @@ QString QStandardPaths::writableLocation(StandardLocation type) case CacheLocation: case GenericCacheLocation: { + if (isTestModeEnabled()) + return QDir::homePath() + "/.qttest/cache"_L1; + // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); - if (isTestModeEnabled()) - xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1; if (xdgCacheHome.isEmpty()) xdgCacheHome = QDir::homePath() + "/.cache"_L1; if (type == QStandardPaths::CacheLocation) @@ -194,9 +195,10 @@ QString QStandardPaths::writableLocation(StandardLocation type) case AppLocalDataLocation: case GenericDataLocation: { - QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); if (isTestModeEnabled()) - xdgDataHome = QDir::homePath() + "/.qttest/share"_L1; + return QDir::homePath() + "/.qttest/share"_L1; + + QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); if (xdgDataHome.isEmpty()) xdgDataHome = QDir::homePath() + "/.local/share"_L1; if (type == AppDataLocation || type == AppLocalDataLocation) @@ -207,10 +209,11 @@ QString QStandardPaths::writableLocation(StandardLocation type) case GenericConfigLocation: case AppConfigLocation: { + if (isTestModeEnabled()) + return QDir::homePath() + "/.qttest/config"_L1; + // http://standards.freedesktop.org/basedir-spec/latest/ QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); - if (isTestModeEnabled()) - xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1; if (xdgConfigHome.isEmpty()) xdgConfigHome = QDir::homePath() + "/.config"_L1; if (type == AppConfigLocation) @@ -253,7 +256,7 @@ QString QStandardPaths::writableLocation(StandardLocation type) if (!key.isEmpty() && !isTestModeEnabled() && file.open(QIODevice::ReadOnly)) { QTextStream stream(&file); // Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop" - QRegularExpression exp("^XDG_(.*)_DIR=(.*)$"_L1); + static const QRegularExpression exp(u"^XDG_(.*)_DIR=(.*)$"_s); QString result; while (!stream.atEnd()) { const QString &line = stream.readLine(); |