Add QStandardPaths::RuntimeLocation, for sockets ($XDG_RUNTIME_DIR)
Change-Id: I19c36a04a9deae49ffc20fdec6a2a7eb05155cb4 Reviewed-by: Thiago Macieira (Intel) <thiago.macieira@intel.com>
This commit is contained in:
parent
4b72c3f434
commit
ddc093b90e
@ -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
|
||||
|
||||
|
@ -71,6 +71,7 @@ public:
|
||||
DataLocation,
|
||||
CacheLocation,
|
||||
GenericDataLocation,
|
||||
RuntimeLocation,
|
||||
ConfigLocation
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user