summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qfileinfo.h
diff options
context:
space:
mode:
authorRyan Chu <ryan.chu@qt.io>2019-07-11 13:23:59 +0200
committerRyan Chu <ryan.chu@qt.io>2019-08-16 23:25:33 +0200
commit7a4e5e7433afe7150cdf40025d4525277809c412 (patch)
tree47161c2c289bee5c636ab36868e265287d3a1d5a /src/corelib/io/qfileinfo.h
parent7ac6cefd8affc1f3bf963035c4ce4184a6023c5a (diff)
Make Qt aware of symlinks and shortcuts on Windows
Qt has traditionally considered Windows shortcut files equivalent to symlinks on Unix file systems. Because of NTFS symlinks, the interpretation of shotcut files as symlinks is confusing. In this change, QFileInfo treats shortcut (.lnk) files as regular files but can follow the pointed object. In addition, QFileInfo introduces a more comprehensive file type. So that applications can make well-informed decisions about how to treat a file system entry. Based on the implementation of QFileInfo::type(), two inline helper functions are introduced to QFileInfo. 1. isSymbolicLink, returns true if it points to a symbolic link. 2. isShortcut, returns true if it points to a shortcut. [ChangeLog][QtCore][QFileInfo] Introduce QFileInfo::type() to replace the isSymLink method. Task-number: QTBUG-75869 Change-Id: Icc0dd52f9ad0ea50b0265d77ee0d0a3d25054e39 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/corelib/io/qfileinfo.h')
-rw-r--r--src/corelib/io/qfileinfo.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h
index 111517325d..1cbeafdd4a 100644
--- a/src/corelib/io/qfileinfo.h
+++ b/src/corelib/io/qfileinfo.h
@@ -66,6 +66,20 @@ public:
QFileInfo(const QFileInfo &fileinfo);
~QFileInfo();
+ enum FileType {
+ Unknown,
+ // base type
+ Regular,
+ Directory,
+ // indirection flag
+ SymbolicLink = 0x10,
+ Shortcut = 0x20,
+ // mask
+ FileTypeMask = 0x0f,
+ LinkTypeMask = 0xf0
+ };
+ Q_DECLARE_FLAGS(FileTypes, FileType)
+
QFileInfo &operator=(const QFileInfo &fileinfo);
QFileInfo &operator=(QFileInfo &&other) noexcept { swap(other); return *this; }
@@ -111,6 +125,8 @@ public:
bool isFile() const;
bool isDir() const;
bool isSymLink() const;
+ inline bool isSymbolicLink() const { return type() & SymbolicLink; }
+ inline bool isShortcut() const { return type() & Shortcut; }
bool isRoot() const;
bool isBundle() const;
@@ -129,6 +145,7 @@ public:
QFile::Permissions permissions() const;
qint64 size() const;
+ FileTypes type() const;
// ### Qt6: inline these functions
#if QT_DEPRECATED_SINCE(5, 10)