From 5f03b48cb38936e2e86143bec71d030876b84c8b Mon Sep 17 00:00:00 2001 From: David Faure Date: Mon, 30 Nov 2015 13:49:33 +0100 Subject: 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 Reviewed-by: Oswald Buddenhagen --- .../io/qstandardpaths/tst_qstandardpaths.cpp | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'tests/auto/corelib/io') diff --git a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp index 24ff2f237f..50c5b938e9 100644 --- a/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp +++ b/tests/auto/corelib/io/qstandardpaths/tst_qstandardpaths.cpp @@ -464,6 +464,15 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() #endif #ifdef Q_XDG_PLATFORM + struct EnvVarRestorer + { + EnvVarRestorer() : origRuntimeDir(qgetenv("XDG_RUNTIME_DIR")) {} + ~EnvVarRestorer() { qputenv("XDG_RUNTIME_DIR", origRuntimeDir.constData()); } + const QByteArray origRuntimeDir; + }; + EnvVarRestorer restorer; + + // When $XDG_RUNTIME_DIR points to a directory with wrong ownership, QStandardPaths should warn qputenv("XDG_RUNTIME_DIR", QFile::encodeName("/tmp")); // It's very unlikely that /tmp is 0600 or that we can chmod it // The call below outputs @@ -474,6 +483,20 @@ void tst_qstandardpaths::testCustomRuntimeDirectory() qPrintable(QString::fromLatin1("QStandardPaths: wrong ownership on runtime directory /tmp, 0 instead of %1").arg(uid))); const QString runtimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); QVERIFY2(runtimeDir.isEmpty(), qPrintable(runtimeDir)); + + // When $XDG_RUNTIME_DIR points to a non-existing directory, QStandardPaths should warn (QTBUG-48771) + qputenv("XDG_RUNTIME_DIR", "does_not_exist"); + QTest::ignoreMessage(QtWarningMsg, "QStandardPaths: XDG_RUNTIME_DIR points to non-existing path 'does_not_exist', please create it with 0700 permissions."); + const QString nonExistingRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + QVERIFY2(nonExistingRuntimeDir.isEmpty(), qPrintable(nonExistingRuntimeDir)); + + // When $XDG_RUNTIME_DIR points to a file, QStandardPaths should warn + const QString file = QFINDTESTDATA("tst_qstandardpaths.cpp"); + QVERIFY(!file.isEmpty()); + qputenv("XDG_RUNTIME_DIR", QFile::encodeName(file)); + QTest::ignoreMessage(QtWarningMsg, qPrintable(QString::fromLatin1("QStandardPaths: XDG_RUNTIME_DIR points to '%1' which is not a directory").arg(file))); + const QString noRuntimeDir = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation); + QVERIFY2(noRuntimeDir.isEmpty(), qPrintable(file)); #endif } -- cgit v1.2.3