From c553f39e3d3cd02854850da0dfc639acbae59299 Mon Sep 17 00:00:00 2001 From: Ahmad Samir Date: Wed, 19 Feb 2025 19:09:59 +0200 Subject: [PATCH] QDirListing: add ExcludeOther Which is the same as ExcludeSpecial (the latter is new in 6.9). This is to match std::filesystem::is_other() which has a similar functionality. This makes it easier to remember/understand both APIs. Amends e583c3d5163a5512abac85e32359652e28a053f7. [ChangeLog][QtCore][QDirListing] Add IteratorFlag::ExcludeOther enumerator. IteratorFlag::ExcludeSpecial now becomes an, obsolete, alias for ExcludeOther (the name was changed to "other" to match the wording used in std::filesystem::is_other()). Change-Id: I986a2d822615f69ccf5ec283756ae063f5e18101 Reviewed-by: Thiago Macieira --- src/corelib/io/qdirlisting.cpp | 18 ++++++++++-------- src/corelib/io/qdirlisting.h | 7 ++++--- src/corelib/io/qfilesystemwatcher_polling_p.h | 2 +- .../corelib/io/qdirlisting/tst_qdirlisting.cpp | 4 ++-- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/corelib/io/qdirlisting.cpp b/src/corelib/io/qdirlisting.cpp index ffac95900cf..b4d425a02b0 100644 --- a/src/corelib/io/qdirlisting.cpp +++ b/src/corelib/io/qdirlisting.cpp @@ -75,15 +75,17 @@ Don't list directories. When combined with ResolveSymlinks, symbolic links to directories will be excluded too. - \value ExcludeSpecial + \omitvalue ExcludeSpecial + \value ExcludeOther Don't list file system entries that are \e not directories, regular files, - nor symbolic links. + or symbolic links. \list - \li On Unix, an example of a special file system entry is a FIFO, socket, - character device, or block device. For more details on Linux, see the - \l{https://www.man7.org/linux/man-pages/man2/mknod.2.html}{mknod manual page}. - \li On Windows (for historical reasons) \c .lnk files are considered special - file system entries. + \li On Unix, a special (other) file system entry is a FIFO, socket, + character device, or block device. For more details see the + \l{https://pubs.opengroup.org/onlinepubs/9699919799/functions/mknod.html}{\c mknod} + manual page. + \li On Windows (for historical reasons) \c .lnk files are considered + special (other) file system entries. \endlist \value ResolveSymlinks @@ -520,7 +522,7 @@ bool QDirListingPrivate::matchesFilters(QDirEntryInfo &entryInfo) const } } - if (iteratorFlags.testAnyFlag(F::ExcludeSpecial) + if (iteratorFlags.testAnyFlag(F::ExcludeOther) && !entryInfo.isFile() && !entryInfo.isDir() && !entryInfo.isSymLink()) { return false; } diff --git a/src/corelib/io/qdirlisting.h b/src/corelib/io/qdirlisting.h index 7174e94990d..3374ae6994a 100644 --- a/src/corelib/io/qdirlisting.h +++ b/src/corelib/io/qdirlisting.h @@ -28,10 +28,11 @@ public: Default = 0x000000, ExcludeFiles = 0x000004, ExcludeDirs = 0x000008, - ExcludeSpecial = 0x000010, + QT6_ONLY(ExcludeSpecial = 0x000010,) + ExcludeOther = 0x000010, ResolveSymlinks = 0x000020, - FilesOnly = ExcludeDirs | ExcludeSpecial, - DirsOnly = ExcludeFiles | ExcludeSpecial, + FilesOnly = ExcludeDirs | ExcludeOther, + DirsOnly = ExcludeFiles | ExcludeOther, IncludeHidden = 0x000040, IncludeDotAndDotDot = 0x000080, CaseSensitive = 0x000100, diff --git a/src/corelib/io/qfilesystemwatcher_polling_p.h b/src/corelib/io/qfilesystemwatcher_polling_p.h index ba252706998..80d7b7d1526 100644 --- a/src/corelib/io/qfilesystemwatcher_polling_p.h +++ b/src/corelib/io/qfilesystemwatcher_polling_p.h @@ -46,7 +46,7 @@ class QPollingFileSystemWatcherEngine : public QFileSystemWatcherEngine QStringList fileNames; using F = QDirListing::IteratorFlag; - constexpr auto flags = F::ExcludeSpecial | F::IncludeDotAndDotDot; + constexpr auto flags = F::ExcludeOther | F::IncludeDotAndDotDot; for (const auto &entry : QDirListing(fileInfo.absoluteFilePath(), flags)) fileNames.emplace_back(entry.fileName()); return fileNames; diff --git a/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp b/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp index c161430f53e..50540a65276 100644 --- a/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp +++ b/tests/auto/corelib/io/qdirlisting/tst_qdirlisting.cpp @@ -620,7 +620,7 @@ void tst_QDirListing::recurseWithFilters() const expectedEntries.insert(QString::fromLatin1("recursiveDirs/dir1/textFileB.txt")); expectedEntries.insert(QString::fromLatin1("recursiveDirs/textFileA.txt")); - constexpr auto flags = ItFlag::ExcludeDirs | ItFlag::ExcludeSpecial| ItFlag::Recursive; + constexpr auto flags = ItFlag::ExcludeDirs | ItFlag::ExcludeOther| ItFlag::Recursive; for (const auto &dirEntry : QDirListing(u"recursiveDirs/"_s, QStringList{u"*.txt"_s}, flags)) actualEntries.insert(dirEntry.filePath()); @@ -640,7 +640,7 @@ void tst_QDirListing::longPath() dirName.append('x'); } - constexpr auto flags = ItFlag::ExcludeFiles | ItFlag::ExcludeSpecial| ItFlag::Recursive; + constexpr auto flags = ItFlag::ExcludeFiles | ItFlag::ExcludeOther| ItFlag::Recursive; QDirListing dirList(dir.absolutePath(), flags); qsizetype m = 0; for (auto it = dirList.begin(); it != dirList.end(); ++it)