summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJani Heikkinen <jani.heikkinen@qt.io>2025-06-06 09:07:54 +0000
committerJani Heikkinen <jani.heikkinen@qt.io>2025-06-09 06:03:04 +0000
commit15d3c67c1bee5dcfcd2449429a6b9656efa1e020 (patch)
tree6f9a88edf8ab5a03a99438b29a50c92031dee828
parentf417776a3678c47c4f2da4b630ac9a9c96ece138 (diff)
Revert "QFileSystemEngine::tempPath: bypass QDir and go straight to QFSEngine"v6.10.0-beta1
This reverts commit c617cc95934ae3c0896082d61a88487b34cf96be. Reason for revert: QTBUG-137416 Change-Id: Ia715924cca8c38f5b988b3f41ee7b5a277c9c5e4 Reviewed-by: Antti Kokko <antti.kokko@qt.io>
-rw-r--r--src/corelib/io/qfilesystemengine_unix.cpp20
-rw-r--r--tests/auto/corelib/io/qdir/tst_qdir.cpp29
2 files changed, 14 insertions, 35 deletions
diff --git a/src/corelib/io/qfilesystemengine_unix.cpp b/src/corelib/io/qfilesystemengine_unix.cpp
index 61b7ecbde17..eaba1368355 100644
--- a/src/corelib/io/qfilesystemengine_unix.cpp
+++ b/src/corelib/io/qfilesystemengine_unix.cpp
@@ -1858,15 +1858,6 @@ QString QFileSystemEngine::rootPath()
return u"/"_s;
}
-static constexpr QLatin1StringView nativeTempPath() noexcept
-{
- // _PATH_TMP usually ends in '/' and we don't want that
- QLatin1StringView temp = _PATH_TMP ""_L1;
- static_assert(_PATH_TMP[0] == '/', "_PATH_TMP needs to be absolute");
- static_assert(_PATH_TMP[1] != '\0', "Are you really sure _PATH_TMP should be the root dir??");
- return temp;
-}
-
QString QFileSystemEngine::tempPath()
{
#ifdef QT_UNIX_TEMP_PATH_OVERRIDE
@@ -1880,17 +1871,10 @@ QString QFileSystemEngine::tempPath()
temp = QString::fromCFString((CFStringRef)nsPath);
#endif
} else {
- constexpr auto nativeTemp = nativeTempPath();
- temp = nativeTemp;
+ temp = _PATH_TMP ""_L1;
}
}
-
- // the environment variable may also end in '/'
- if (temp.size() > 1 && temp.endsWith(u'/'))
- temp.chop(1);
-
- QFileSystemEntry e(temp, QFileSystemEntry::FromInternalPath{});
- return QFileSystemEngine::absoluteName(e).filePath();
+ return QDir(QDir::cleanPath(temp)).canonicalPath();
#endif
}
diff --git a/tests/auto/corelib/io/qdir/tst_qdir.cpp b/tests/auto/corelib/io/qdir/tst_qdir.cpp
index 99232c852b6..b7313cf5481 100644
--- a/tests/auto/corelib/io/qdir/tst_qdir.cpp
+++ b/tests/auto/corelib/io/qdir/tst_qdir.cpp
@@ -1240,8 +1240,7 @@ void tst_QDir::current()
#if defined(Q_OS_WIN)
QCOMPARE(newCurrent.absolutePath().toLower(), currentDir.toLower());
#else
- // getcwd(2) on Unix returns the canonical path
- QCOMPARE(newCurrent.absolutePath(), QDir(currentDir).canonicalPath());
+ QCOMPARE(newCurrent.absolutePath(), currentDir);
#endif
}
@@ -1255,25 +1254,21 @@ void tst_QDir::cd_data()
QTest::addColumn<bool>("successExpected");
QTest::addColumn<QString>("newDir");
- // use the canonical path for m_dataPath here, because if TMPDIR points to
- // a symlink like what happens on Apple systems (/tmp -> /private/tmp),
- // then /tmp/.. will not be the same as / (it's /private).
- QString canonicalPath = QDir(m_dataPath).canonicalPath();
- int index = canonicalPath.lastIndexOf(QLatin1Char('/'));
- QTest::newRow("cdUp") << canonicalPath << ".." << true << canonicalPath.left(index==0?1:index);
+ int index = m_dataPath.lastIndexOf(QLatin1Char('/'));
+ QTest::newRow("cdUp") << m_dataPath << ".." << true << m_dataPath.left(index==0?1:index);
QTest::newRow("cdUp non existent (relative dir)") << "anonexistingDir" << ".."
- << true << canonicalPath;
- QTest::newRow("cdUp non existent (absolute dir)") << canonicalPath + "/anonexistingDir" << ".."
- << true << canonicalPath;
- QTest::newRow("noChange") << canonicalPath << "." << true << canonicalPath;
+ << true << m_dataPath;
+ QTest::newRow("cdUp non existent (absolute dir)") << m_dataPath + "/anonexistingDir" << ".."
+ << true << m_dataPath;
+ QTest::newRow("noChange") << m_dataPath << "." << true << m_dataPath;
#if defined(Q_OS_WIN) // on windows QDir::root() is usually c:/ but cd "/" will not force it to be root
- QTest::newRow("absolute") << canonicalPath << "/" << true << "/";
+ QTest::newRow("absolute") << m_dataPath << "/" << true << "/";
#else
- QTest::newRow("absolute") << canonicalPath << "/" << true << QDir::root().absolutePath();
+ QTest::newRow("absolute") << m_dataPath << "/" << true << QDir::root().absolutePath();
#endif
- QTest::newRow("non existant") << "." << "../anonexistingdir" << false << canonicalPath;
- QTest::newRow("self") << "." << (QString("../") + QFileInfo(canonicalPath).fileName()) << true << canonicalPath;
- QTest::newRow("file") << "." << "qdir.pro" << false << canonicalPath;
+ QTest::newRow("non existant") << "." << "../anonexistingdir" << false << m_dataPath;
+ QTest::newRow("self") << "." << (QString("../") + QFileInfo(m_dataPath).fileName()) << true << m_dataPath;
+ QTest::newRow("file") << "." << "qdir.pro" << false << m_dataPath;
}
void tst_QDir::cd()