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.
|
non-essential (cached) data should be written.
|
||||||
\value GenericDataLocation Returns a directory location where persistent
|
\value GenericDataLocation Returns a directory location where persistent
|
||||||
data shared across applications can be stored.
|
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
|
\value ConfigLocation Returns a directory location where user-specific
|
||||||
configuration files should be written.
|
configuration files should be written.
|
||||||
|
|
||||||
@ -118,8 +120,6 @@ QT_BEGIN_NAMESPACE
|
|||||||
starting with the user-specific storageLocation() for the \a type.
|
starting with the user-specific storageLocation() for the \a type.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// TODO add XDG_RUNTIME_DIR?
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\enum QStandardPaths::LocateOption
|
\enum QStandardPaths::LocateOption
|
||||||
|
|
||||||
|
@ -71,6 +71,7 @@ public:
|
|||||||
DataLocation,
|
DataLocation,
|
||||||
CacheLocation,
|
CacheLocation,
|
||||||
GenericDataLocation,
|
GenericDataLocation,
|
||||||
|
RuntimeLocation,
|
||||||
ConfigLocation
|
ConfigLocation
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -77,6 +77,7 @@ OSType translateLocation(QStandardPaths::StandardLocation type)
|
|||||||
case QStandardPaths::TempLocation:
|
case QStandardPaths::TempLocation:
|
||||||
return kTemporaryFolderType;
|
return kTemporaryFolderType;
|
||||||
case QStandardPaths::GenericDataLocation:
|
case QStandardPaths::GenericDataLocation:
|
||||||
|
case QStandardPaths::RuntimeLocation:
|
||||||
case QStandardPaths::DataLocation:
|
case QStandardPaths::DataLocation:
|
||||||
return kApplicationSupportFolderType;
|
return kApplicationSupportFolderType;
|
||||||
case QStandardPaths::CacheLocation:
|
case QStandardPaths::CacheLocation:
|
||||||
@ -126,6 +127,7 @@ QString QStandardPaths::storageLocation(StandardLocation type)
|
|||||||
case GenericDataLocation:
|
case GenericDataLocation:
|
||||||
case DataLocation:
|
case DataLocation:
|
||||||
case CacheLocation:
|
case CacheLocation:
|
||||||
|
case RuntimeLocation:
|
||||||
return macLocation(type, kUserDomain);
|
return macLocation(type, kUserDomain);
|
||||||
default:
|
default:
|
||||||
return macLocation(type, kOnAppropriateDisk);
|
return macLocation(type, kOnAppropriateDisk);
|
||||||
|
@ -46,6 +46,8 @@
|
|||||||
#include <qfile.h>
|
#include <qfile.h>
|
||||||
#include <qtextstream.h>
|
#include <qtextstream.h>
|
||||||
#include <qcoreapplication.h>
|
#include <qcoreapplication.h>
|
||||||
|
#include <private/qfilesystemengine_p.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifndef QT_NO_STANDARDPATHS
|
#ifndef QT_NO_STANDARDPATHS
|
||||||
@ -93,6 +95,38 @@ QString QStandardPaths::storageLocation(StandardLocation type)
|
|||||||
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
|
||||||
return xdgConfigHome;
|
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:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -159,16 +159,14 @@ QString QStandardPaths::storageLocation(StandardLocation type)
|
|||||||
// cache directory located in their AppData directory
|
// cache directory located in their AppData directory
|
||||||
return storageLocation(DataLocation) + QLatin1String("\\cache");
|
return storageLocation(DataLocation) + QLatin1String("\\cache");
|
||||||
|
|
||||||
case QStandardPaths::HomeLocation:
|
case RuntimeLocation:
|
||||||
|
case HomeLocation:
|
||||||
result = QDir::homePath();
|
result = QDir::homePath();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QStandardPaths::TempLocation:
|
case TempLocation:
|
||||||
result = QDir::tempPath();
|
result = QDir::tempPath();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user