summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
diff options
context:
space:
mode:
authorRyan Chu <ryan.chu@qt.io>2019-08-21 16:18:07 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2019-11-09 00:47:45 +0100
commit004e3e0dc2cab4a4534d2ed3ace41aad6bfbe45d (patch)
tree89648f07e55a607a7d38e0f7b6eecb81b5607a66 /tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
parentb81863cfad1ca1e5825eaffb50a9b2fe2da51c7f (diff)
Make Qt aware of NTFS Junctions on Windows
On NTFS, a junction point can be created and deleted by the mklink and rmdir commands, respectively. If a directory is not identified correctly as a junction, then applications will likely try to remove it using recursive methods, leading to fatal data loss. With this change, Qt can identify file system entries as junctions, allowing applications to use the correct file system operation to remove it. The test needs to delay the cleaning up of junctions and files it creates until the checks are complete; since they might fail and make the test function return prematurely, use a scope guard. [ChangeLog][QtCore][QFileInfo] Add QFileInfo::isJunction so that applications can recognize NTFS file system entries as junctions Task-number: QTBUG-75869 Change-Id: I3c208245afbd9fb7555515fb776ff63b133ca858 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp')
-rw-r--r--tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp25
1 files changed, 14 insertions, 11 deletions
diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
index 0597a7d521..09ef0ea44f 100644
--- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
+++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp
@@ -1813,19 +1813,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks()
QVERIFY2(creationResult == ERROR_SUCCESS, qPrintable(errorMessage));
QFileInfo fi(path);
- const bool actualIsSymLink = fi.isSymbolicLink();
+ auto guard = qScopeGuard([&fi, this]() {
+ // Ensure that junctions, mountpoints are removed. If this fails, do not remove
+ // temporary directory to prevent it from trashing the system.
+ if (fi.isDir()) {
+ if (!QDir().rmdir(fi.filePath())) {
+ qWarning("Unable to remove NTFS junction '%ls', keeping '%ls'.",
+ qUtf16Printable(fi.fileName()),
+ qUtf16Printable(QDir::toNativeSeparators(m_dir.path())));
+ m_dir.setAutoRemove(false);
+ }
+ }
+ });
const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString();
const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString();
- // Ensure that junctions, mountpoints are removed. If this fails, do not remove
- // temporary directory to prevent it from trashing the system.
- if (fi.isDir()) {
- if (!QDir().rmdir(fi.filePath())) {
- qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.",
- qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path())));
- m_dir.setAutoRemove(false);
- }
- }
- QCOMPARE(actualIsSymLink, isSymLink);
+ QCOMPARE(fi.isJunction(), resource.type == NtfsTestResource::Junction);
+ QCOMPARE(fi.isSymbolicLink(), isSymLink);
if (isSymLink) {
QCOMPARE(actualSymLinkTarget, linkTarget);
QCOMPARE(actualCanonicalFilePath, canonicalFilePath);