diff options
author | Daniel Molkentin <daniel.molkentin@nokia.com> | 2010-01-27 17:15:55 (GMT) |
---|---|---|
committer | Daniel Molkentin <daniel.molkentin@nokia.com> | 2010-01-27 17:15:55 (GMT) |
commit | 3093340cd24874bf79072d1cb6aaefa3ddc1d939 (patch) | |
tree | 01677ff1c59b79e04e12229d047f43d4233acd19 /src/corelib | |
parent | 7a2f867546ed8c40b77b533c0cd21d4f3d2e9cd5 (diff) | |
download | Qt-3093340cd24874bf79072d1cb6aaefa3ddc1d939.zip Qt-3093340cd24874bf79072d1cb6aaefa3ddc1d939.tar.gz Qt-3093340cd24874bf79072d1cb6aaefa3ddc1d939.tar.bz2 |
Fix QSettings default paths not being initialized when setPath() is called
This only coincidently worked on Linux, because it creates a QSettings
object to read system settings before any user data was executed, thus
initializing the static default path data. However, if only the
SystemPath was modified, the UserPath never got initialized on
non-Linux platforms, causing settings for the users below $PWD.
Also, it removes unncessary checks and mutex locks, which should
give a slight speed up.
Reviewed-By: dt
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qsettings.cpp | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/src/corelib/io/qsettings.cpp b/src/corelib/io/qsettings.cpp index 2c31509..64015ce 100644 --- a/src/corelib/io/qsettings.cpp +++ b/src/corelib/io/qsettings.cpp @@ -1091,30 +1091,23 @@ static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope) return int((uint(format) << 1) | uint(scope == QSettings::SystemScope)); } -static QString getPath(QSettings::Format format, QSettings::Scope scope) +static void initDefaultPaths(QMutexLocker *locker) { - Q_ASSERT((int)QSettings::NativeFormat == 0); - Q_ASSERT((int)QSettings::IniFormat == 1); - + PathHash *pathHash = pathHashFunc(); QString homePath = QDir::homePath(); QString systemPath; - QMutexLocker locker(globalMutex()); - PathHash *pathHash = pathHashFunc(); - bool loadSystemPath = pathHash->isEmpty(); - locker.unlock(); - - if (loadSystemPath) { - /* - QLibraryInfo::location() uses QSettings, so in order to - avoid a dead-lock, we can't hold the global mutex while - calling it. - */ - systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); - systemPath += QLatin1Char('/'); - } + locker->unlock(); + + /* + QLibraryInfo::location() uses QSettings, so in order to + avoid a dead-lock, we can't hold the global mutex while + calling it. + */ + systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); + systemPath += QLatin1Char('/'); - locker.relock(); + locker->relock(); if (pathHash->isEmpty()) { /* Lazy initialization of pathHash. We initialize the @@ -1155,6 +1148,17 @@ static QString getPath(QSettings::Format format, QSettings::Scope scope) #endif #endif } +} + +static QString getPath(QSettings::Format format, QSettings::Scope scope) +{ + Q_ASSERT((int)QSettings::NativeFormat == 0); + Q_ASSERT((int)QSettings::IniFormat == 1); + + QMutexLocker locker(globalMutex()); + PathHash *pathHash = pathHashFunc(); + if (pathHash->isEmpty()) + initDefaultPaths(&locker); QString result = pathHash->value(pathHashKey(format, scope)); if (!result.isEmpty()) @@ -3455,6 +3459,8 @@ void QSettings::setPath(Format format, Scope scope, const QString &path) { QMutexLocker locker(globalMutex()); PathHash *pathHash = pathHashFunc(); + if (pathHash->isEmpty()) + initDefaultPaths(&locker); pathHash->insert(pathHashKey(format, scope), path + QDir::separator()); } |