diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-05-31 16:25:21 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2021-06-05 01:16:06 +0200 |
commit | ded82d1b073adb769afd28104515d240e8e1dd3f (patch) | |
tree | 933acea7f79e2e21af71e9e38c37868974a87d7e /tests | |
parent | 0564ebdb3641d7325f73dbbf2cbb04e6dca92d83 (diff) |
Implement QFileInfo::junctionTarget(), adjust auto-test
The change in 004e3e0dc2cab4a4534d2ed3ace41aad6bfbe45d introduces
Windows junction awareness, though users were still unable to resolve
the junction target. This change adds the ability to solve this.
Fixes: QTBUG-93869
Change-Id: I9f4d4ed87b92e757f7b6d8739e2a61b58c096f63
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp | 28 | ||||
-rw-r--r-- | tests/benchmarks/corelib/io/qfileinfo/main.cpp | 10 |
2 files changed, 30 insertions, 8 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index 916b084e24..4d74fe4d98 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -1782,14 +1782,36 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() } } }); - const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString(); - const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString(); + const QString actualCanonicalFilePath = fi.canonicalFilePath(); QCOMPARE(fi.isJunction(), isJunction); QCOMPARE(fi.isSymbolicLink(), isSymLink); if (isSymLink) { - QCOMPARE(actualSymLinkTarget, linkTarget); + QCOMPARE(fi.symLinkTarget(), linkTarget); QCOMPARE(actualCanonicalFilePath, canonicalFilePath); } + + if (isJunction) { + if (creationResult.target.startsWith(uR"(\??\)")) + creationResult.target = creationResult.target.sliced(4); + + // resolve volume to drive letter + static const QRegularExpression matchVolumeRe(uR"(^Volume\{([a-z]|[0-9]|-)+\}\\)"_qs, + QRegularExpression::CaseInsensitiveOption); + auto matchVolume = matchVolumeRe.match(creationResult.target); + if (matchVolume.hasMatch()) { + Q_ASSERT(matchVolume.capturedStart() == 0); + DWORD len; + wchar_t buffer[MAX_PATH]; + const QString volumeName = uR"(\\?\)"_qs + matchVolume.captured(); + if (GetVolumePathNamesForVolumeName(reinterpret_cast<LPCWSTR>(volumeName.utf16()), + buffer, MAX_PATH, &len) != 0) { + creationResult.target.replace(0, matchVolume.capturedLength(), + QString::fromWCharArray(buffer)); + } + } + QCOMPARE(fi.junctionTarget(), QDir::fromNativeSeparators(creationResult.target)); + QCOMPARE(actualCanonicalFilePath, QFileInfo(creationResult.link).canonicalFilePath()); + } } void tst_QFileInfo::brokenShortcut() diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp index 65b712898b..2cd06eef27 100644 --- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp +++ b/tests/benchmarks/corelib/io/qfileinfo/main.cpp @@ -43,7 +43,7 @@ private slots: void existsStatic(); #if defined(Q_OS_WIN) void symLinkTargetPerformanceLNK(); - void symLinkTargetPerformanceMounpoint(); + void junctionTargetPerformanceMountpoint(); #endif void initTestCase(); void cleanupTestCase(); @@ -86,7 +86,7 @@ void qfileinfo::symLinkTargetPerformanceLNK() QVERIFY(QFile::remove("link.lnk")); } -void qfileinfo::symLinkTargetPerformanceMounpoint() +void qfileinfo::junctionTargetPerformanceMountpoint() { wchar_t buffer[MAX_PATH]; QString rootPath = QDir::toNativeSeparators(QDir::rootPath()); @@ -99,11 +99,11 @@ void qfileinfo::symLinkTargetPerformanceMounpoint() QFileInfo info(mountpoint); info.setCaching(false); - QVERIFY(info.isSymLink()); - QString linkTarget; + QVERIFY(info.isJunction()); + QString junctionTarget; QBENCHMARK { for(int i=0; i<100; i++) - linkTarget = info.symLinkTarget(); + junctionTarget = info.junctionTarget(); } QVERIFY(QDir().rmdir(mountpoint)); } |