summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Faure <david.faure@kdab.com>2015-11-30 13:49:33 +0100
committerDavid Faure <david.faure@kdab.com>2015-12-22 09:56:23 +0000
commit5f03b48cb38936e2e86143bec71d030876b84c8b (patch)
treef13fcde62d6f187c26744db342af9adf0ccad6bb /src
parent4d9e06fa5346858bed41880917a850964acae225 (diff)
QStandardPaths: warn if $XDG_RUNTIME_DIR doesn't exist
If the environment variable is set, but points to a non-existing directory, the user would get a warning about chmod failing. Better be clear and warn about the fact that the directory itself doesn't exist. Also warn if $XDG_RUNTIME_DIR points to a file rather than a directory. Task-number: QTBUG-48771 Change-Id: If84e72d768528ea4b80260afbbc18709b7b738a8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index ed2faa742a..78f75482ea 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -113,21 +113,33 @@ QString QStandardPaths::writableLocation(StandardLocation type)
{
const uid_t myUid = geteuid();
// http://standards.freedesktop.org/basedir-spec/latest/
+ QFileInfo fileInfo;
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()) {
+ fileInfo.setFile(xdgRuntimeDir);
+ if (!fileInfo.isDir()) {
if (!QDir().mkdir(xdgRuntimeDir)) {
qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno)));
return QString();
}
}
qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%s'", qPrintable(xdgRuntimeDir));
+ } else {
+ fileInfo.setFile(xdgRuntimeDir);
+ if (!fileInfo.exists()) {
+ qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%s', "
+ "please create it with 0700 permissions.", qPrintable(xdgRuntimeDir));
+ return QString();
+ }
+ if (!fileInfo.isDir()) {
+ qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%s' which is not a directory",
+ qPrintable(xdgRuntimeDir));
+ 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);
@@ -135,13 +147,15 @@ QString QStandardPaths::writableLocation(StandardLocation type)
}
// "and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700."
// since the current user is the owner, set both xxxUser and xxxOwner
- QFile file(xdgRuntimeDir);
const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser
| QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner;
- if (file.permissions() != wantedPerms && !file.setPermissions(wantedPerms)) {
- qWarning("QStandardPaths: could not set correct permissions on runtime directory %s: %s",
- qPrintable(xdgRuntimeDir), qPrintable(file.errorString()));
- return QString();
+ if (fileInfo.permissions() != wantedPerms) {
+ QFile file(xdgRuntimeDir);
+ if (!file.setPermissions(wantedPerms)) {
+ qWarning("QStandardPaths: could not set correct permissions on runtime directory %s: %s",
+ qPrintable(xdgRuntimeDir), qPrintable(file.errorString()));
+ return QString();
+ }
}
return xdgRuntimeDir;
}