From 7a4e5e7433afe7150cdf40025d4525277809c412 Mon Sep 17 00:00:00 2001 From: Ryan Chu Date: Thu, 11 Jul 2019 13:23:59 +0200 Subject: 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 --- src/corelib/io/qfileinfo.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/corelib/io/qfileinfo.h') 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) -- cgit v1.2.3