diff options
author | David Faure <faure@kde.org> | 2011-10-21 20:57:54 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-10-23 00:56:56 +0200 |
commit | ddc093b90e26b2f5291ee70f9d752607429cd81a (patch) | |
tree | 0a69f3ef97cd45419b6c0d661996255259e59a30 /src/corelib | |
parent | 4b72c3f4347bfb8493e877d26f172f2e18c69a83 (diff) |
Add QStandardPaths::RuntimeLocation, for sockets ($XDG_RUNTIME_DIR)
Change-Id: I19c36a04a9deae49ffc20fdec6a2a7eb05155cb4
Reviewed-by: Thiago Macieira (Intel) <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/io/qstandardpaths.cpp | 4 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths.h | 1 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_mac.cpp | 2 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 34 | ||||
-rw-r--r-- | src/corelib/io/qstandardpaths_win.cpp | 8 |
5 files changed, 42 insertions, 7 deletions
diff --git a/src/corelib/io/qstandardpaths.cpp b/src/corelib/io/qstandardpaths.cpp index 86d0f7424d..552bb21972 100644 --- a/src/corelib/io/qstandardpaths.cpp +++ b/src/corelib/io/qstandardpaths.cpp @@ -85,6 +85,8 @@ QT_BEGIN_NAMESPACE non-essential (cached) data should be written. \value GenericDataLocation Returns a directory location where persistent data shared across applications can be stored. + \value RuntimeLocation Returns a directory location where runtime communication + files should be written. For instance unix local sockets. \value ConfigLocation Returns a directory location where user-specific configuration files should be written. @@ -118,8 +120,6 @@ QT_BEGIN_NAMESPACE starting with the user-specific storageLocation() for the \a type. */ -// TODO add XDG_RUNTIME_DIR? - /*! \enum QStandardPaths::LocateOption diff --git a/src/corelib/io/qstandardpaths.h b/src/corelib/io/qstandardpaths.h index d0293ab3fd..ac2a17ddc8 100644 --- a/src/corelib/io/qstandardpaths.h +++ b/src/corelib/io/qstandardpaths.h @@ -71,6 +71,7 @@ public: DataLocation, CacheLocation, GenericDataLocation, + RuntimeLocation, ConfigLocation }; diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index a13162cc7b..4f379fac09 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -77,6 +77,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type) case QStandardPaths::TempLocation: return kTemporaryFolderType; case QStandardPaths::GenericDataLocation: + case QStandardPaths::RuntimeLocation: case QStandardPaths::DataLocation: return kApplicationSupportFolderType; case QStandardPaths::CacheLocation: @@ -126,6 +127,7 @@ QString QStandardPaths::storageLocation(StandardLocation type) case GenericDataLocation: case DataLocation: case CacheLocation: + case RuntimeLocation: return macLocation(type, kUserDomain); default: return macLocation(type, kOnAppropriateDisk); diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 5a52c2518f..12f872f5fa 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -46,6 +46,8 @@ #include <qfile.h> #include <qtextstream.h> #include <qcoreapplication.h> +#include <private/qfilesystemengine_p.h> +#include <errno.h> #include <stdlib.h> #ifndef QT_NO_STANDARDPATHS @@ -93,6 +95,38 @@ QString QStandardPaths::storageLocation(StandardLocation type) xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); return xdgConfigHome; } + case RuntimeLocation: + { + const uid_t myUid = geteuid(); + // http://standards.freedesktop.org/basedir-spec/latest/ + QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR")); + if (xdgRuntimeDir.isEmpty()) { + const QString userName = QFileSystemEngine::resolveUserName(myUid); + xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName; + QDir dir(xdgRuntimeDir); + if (!dir.exists()) { + if (!QDir().mkdir(xdgRuntimeDir)) { + qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno))); + return QString(); + } + } + } + // "The directory MUST be owned by the user" + QFileInfo fileInfo(xdgRuntimeDir); + if (fileInfo.ownerId() != myUid) { + qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir), + fileInfo.ownerId(), myUid); + return QString(); + } + // "and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700." + QFile file(xdgRuntimeDir); + const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser; + if (file.permissions() != wantedPerms && !file.setPermissions(wantedPerms)) { + qWarning("QStandardPaths: wrong permissions on runtime directory %s", qPrintable(xdgRuntimeDir)); + return QString(); + } + return xdgRuntimeDir; + } default: break; } diff --git a/src/corelib/io/qstandardpaths_win.cpp b/src/corelib/io/qstandardpaths_win.cpp index 497e09e0e2..bd327e6f37 100644 --- a/src/corelib/io/qstandardpaths_win.cpp +++ b/src/corelib/io/qstandardpaths_win.cpp @@ -159,16 +159,14 @@ QString QStandardPaths::storageLocation(StandardLocation type) // cache directory located in their AppData directory return storageLocation(DataLocation) + QLatin1String("\\cache"); - case QStandardPaths::HomeLocation: + case RuntimeLocation: + case HomeLocation: result = QDir::homePath(); break; - case QStandardPaths::TempLocation: + case TempLocation: result = QDir::tempPath(); break; - - default: - break; } return result; } |