Revert "QFileSystemEngine::tempPath: bypass QDir and go straight to QFSEngine"
This reverts commit c617cc95934ae3c0896082d61a88487b34cf96be. Reason for revert: QTBUG-137416 Change-Id: Ia715924cca8c38f5b988b3f41ee7b5a277c9c5e4 Reviewed-by: Antti Kokko <antti.kokko@qt.io>
This commit is contained in:
parent
f417776a36
commit
15d3c67c1b
@ -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
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user