diff options
author | Ryan Chu <ryan.chu@qt.io> | 2019-08-21 16:18:07 +0200 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2019-11-09 00:47:45 +0100 |
commit | 004e3e0dc2cab4a4534d2ed3ace41aad6bfbe45d (patch) | |
tree | 89648f07e55a607a7d38e0f7b6eecb81b5607a66 /src/corelib/io/qfileinfo.cpp | |
parent | b81863cfad1ca1e5825eaffb50a9b2fe2da51c7f (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 'src/corelib/io/qfileinfo.cpp')
-rw-r--r-- | src/corelib/io/qfileinfo.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index 89834de29f..93696c1320 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -1145,6 +1145,25 @@ bool QFileInfo::isShortcut() const [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); } + +/*! + Returns \c true if the object points to a junction; + otherwise returns \c false. + + Junctions only exist on Windows' NTFS file system, and are typically + created by the \c{mklink} command. They can be thought of as symlinks for + directories, and can only be created for absolute paths on the local + volume. +*/ +bool QFileInfo::isJunction() const +{ + Q_D(const QFileInfo); + return d->checkAttribute<bool>( + QFileSystemMetaData::LegacyLinkType, + [d]() { return d->metaData.isJunction(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); +} + /*! Returns \c true if the object points to a directory or to a symbolic link to a directory, and that directory is the root directory; otherwise |