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 <thiago.macieira@intel.com>
This commit is contained in:
Ahmad Samir 2025-02-19 19:09:59 +02:00
parent 3caf64adda
commit c553f39e3d
4 changed files with 17 additions and 14 deletions

View File

@ -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;
}

View File

@ -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,

View File

@ -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;

View File

@ -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)