From ca3be922349d5fa282578fbb6c1dc2bd25d1f5aa Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Thu, 29 Aug 2019 16:22:53 +0200 Subject: Remove QFileInfo::type and related enum from 5.14 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The API is problematic for several reasons: - the mixing of flags and enum in a single enum type - the name "type" as somewhat overloaded - the ease of misuse when comparing the result rather than testing for a bit being set In light of this, focus for 5.14 on the new isShortcut and isSymbolicLink functions, thus migitating the problematic isSymLink which conflates the two concepts. Change-Id: I57e02321edd5061f69a775f04a0932ef89adf866 Reviewed-by: Tor Arne Vestbø Reviewed-by: Marc Mutz --- src/corelib/io/qfileinfo.cpp | 93 +++++++++++++------------------------------- src/corelib/io/qfileinfo.h | 19 +-------- 2 files changed, 29 insertions(+), 83 deletions(-) (limited to 'src/corelib/io') diff --git a/src/corelib/io/qfileinfo.cpp b/src/corelib/io/qfileinfo.cpp index b720966d8f..a6f8b45ea3 100644 --- a/src/corelib/io/qfileinfo.cpp +++ b/src/corelib/io/qfileinfo.cpp @@ -310,19 +310,6 @@ QDateTime &QFileInfoPrivate::getFileTime(QAbstractFileEngine::FileTime request) \sa QDir, QFile */ -/*! - \enum QFileInfo::FileType - - This enum is returned by type() to describe the type of the file system - entity described by the QFileInfo object. - - \value Unknown The object refers to an unknown item. - \value Regular The object refers to a regular file. - \value Directory The object refers to a directory. - \value SymbolicLink The object refers to a symbolic link. - \value Shortcut The object refers to a shortcut. -*/ - /*! \fn QFileInfo &QFileInfo::operator=(QFileInfo &&other) @@ -1008,7 +995,11 @@ bool QFileInfo::isNativePath() const */ bool QFileInfo::isFile() const { - return (type() & FileTypeMask) == Regular; + Q_D(const QFileInfo); + return d->checkAttribute( + QFileSystemMetaData::FileType, + [d]() { return d->metaData.isFile(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::FileType); }); } /*! @@ -1019,7 +1010,11 @@ bool QFileInfo::isFile() const */ bool QFileInfo::isDir() const { - return (type() & FileTypeMask) == Directory; + Q_D(const QFileInfo); + return d->checkAttribute( + QFileSystemMetaData::DirectoryType, + [d]() { return d->metaData.isDirectory(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::DirectoryType); }); } @@ -1070,8 +1065,6 @@ bool QFileInfo::isSymLink() const } /*! - \fn bool QFileInfo::isSymbolicLink() const - Returns \c true if this object points to a symbolic link; otherwise returns \c false. @@ -1091,9 +1084,16 @@ bool QFileInfo::isSymLink() const \sa isFile(), isDir(), isShortcut(), symLinkTarget() */ -/*! - \fn bool QFileInfo::isShortcut() const +bool QFileInfo::isSymbolicLink() const +{ + Q_D(const QFileInfo); + return d->checkAttribute( + QFileSystemMetaData::LegacyLinkType, + [d]() { return d->metaData.isLink(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); +} +/*! Returns \c true if this object points to a shortcut; otherwise returns \c false. @@ -1110,6 +1110,14 @@ bool QFileInfo::isSymLink() const \sa isFile(), isDir(), isSymbolicLink(), symLinkTarget() */ +bool QFileInfo::isShortcut() const +{ + Q_D(const QFileInfo); + return d->checkAttribute( + QFileSystemMetaData::LegacyLinkType, + [d]() { return d->metaData.isLnkFile(); }, + [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); }); +} /*! Returns \c true if the object points to a directory or to a symbolic @@ -1314,53 +1322,6 @@ qint64 QFileInfo::size() const }); } -/*! - Returns the QFileInfo::FileTypes. - - QFileInfo::FileTypes combines with an indirection flag (link type) and a - base type it refers to. - - For example, \c SymbolicLink combines with \c Regular meaning a symlink to - a regular file. - - In addition, FileTypeMask and LinkTypeMask are used to extract the base - type and link type respectively. - - \sa isFile(), isDir(), isShortcut(), isSymbolicLink() -*/ -QFileInfo::FileTypes QFileInfo::type() const -{ - Q_D(const QFileInfo); - - QFileInfo::FileTypes type = QFileInfo::Unknown; - if (d->checkAttribute( - QFileSystemMetaData::LegacyLinkType, - [d]() { return d->metaData.isLnkFile(); }, - [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); })) { - type = QFileInfo::Shortcut; - } else if (d->checkAttribute( - QFileSystemMetaData::LegacyLinkType, - [d]() { return d->metaData.isLink(); }, - [d]() { return d->getFileFlags(QAbstractFileEngine::LinkType); })) { - type = QFileInfo::SymbolicLink; - } - - if (d->checkAttribute( - QFileSystemMetaData::DirectoryType, - [d]() { return d->metaData.isDirectory(); }, - [d]() { return d->getFileFlags(QAbstractFileEngine::DirectoryType); })) { - return type | QFileInfo::Directory; - } - - if (d->checkAttribute( - QFileSystemMetaData::FileType, - [d]() { return d->metaData.isFile(); }, - [d]() { return d->getFileFlags(QAbstractFileEngine::FileType); })) { - return type | QFileInfo::Regular; - } - return type; -} - #if QT_DEPRECATED_SINCE(5, 10) /*! \deprecated diff --git a/src/corelib/io/qfileinfo.h b/src/corelib/io/qfileinfo.h index 1cbeafdd4a..3ac028085a 100644 --- a/src/corelib/io/qfileinfo.h +++ b/src/corelib/io/qfileinfo.h @@ -66,20 +66,6 @@ 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; } @@ -125,8 +111,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 isSymbolicLink() const; + bool isShortcut() const; bool isRoot() const; bool isBundle() const; @@ -145,7 +131,6 @@ 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