151 QDirListing::IteratorFlags listerFlags;
153 if (flags & QDirIterator::NoIteratorFlags)
154 listerFlags.setFlag(F::Default);
155 if (flags & QDirIterator::FollowSymlinks)
156 listerFlags.setFlag(F::FollowDirSymlinks);
157 if (flags & QDirIterator::Subdirectories)
158 listerFlags.setFlag(F::Recursive);
219 if (nameFilters.contains(
"*"_L1))
223 if (legacyDirFilters == QDir::NoFilter)
224 legacyDirFilters = QDir::AllEntries;
227#if QT_CONFIG(regularexpression)
228 nameRegExps.reserve(nameFilters.size());
230 const bool isCase = [
this] {
231 if (useLegacyFilters)
232 return legacyDirFilters.testAnyFlags(QDir::CaseSensitive);
233 return iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::CaseSensitive);
236 const auto cs = isCase ? Qt::CaseSensitive : Qt::CaseInsensitive;
237 for (
const auto &filter : nameFilters)
238 nameRegExps.emplace_back(QRegularExpression::fromWildcard(filter, cs));
242 engine = QFileSystemEngine::createLegacyEngine(initialEntryInfo.entry,
243 initialEntryInfo.metaData);
265 const QString path = [&entryInfo] {
267 if (entryInfo.isSymLink())
268 return entryInfo.canonicalFilePath();
270 return entryInfo.filePath();
274 if (iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::FollowDirSymlinks)) {
276 if (visitedLinks.hasSeen(entryInfo.canonicalFilePath()))
281 engine->setFileName(path);
282 if (
auto it = engine->beginEntryList(path, iteratorFlags, nameFilters)) {
283 fileEngineIterators.emplace_back(std::move(it));
288#ifndef QT_NO_FILESYSTEMITERATOR
289 QFileSystemEntry *fentry =
nullptr;
290 if (entryInfo.fileInfoOpt)
291 fentry = &entryInfo.fileInfoOpt->d_ptr->fileEntry;
293 fentry = &entryInfo.entry;
294 nativeIterators.emplace_back(std::make_unique<QFileSystemIterator>(*fentry, iteratorFlags));
296 qWarning(
"Qt was built with -no-feature-filesystemiterator: no files/plugins will be found!");
330 while (!fileEngineIterators.empty()) {
332 QAbstractFileEngineIterator *it;
333 while (it = fileEngineIterators.back().get(), it->advance()) {
334 QDirEntryInfo entryInfo;
335 entryInfo.fileInfoOpt = it->currentFileInfo();
336 if (entryMatches(entryInfo)) {
337 currentEntryInfo = std::move(entryInfo);
342 fileEngineIterators.pop_back();
345#ifndef QT_NO_FILESYSTEMITERATOR
346 QDirEntryInfo entryInfo;
347 while (!nativeIterators.empty()) {
349 QFileSystemIterator *it;
350 while (it = nativeIterators.back().get(),
351 it->advance(entryInfo.entry, entryInfo.metaData)) {
352 if (entryMatches(entryInfo)) {
353 currentEntryInfo = std::move(entryInfo);
359 nativeIterators.pop_back();
374 if (!iteratorFlags.testAnyFlags(F::Recursive))
378 if (!iteratorFlags.testAnyFlags(F::FollowDirSymlinks) && entryInfo.isSymLink())
382 if (isDotOrDotDot(entryInfo.fileName()))
386 const bool includeHidden = [
this]() {
387 if (useLegacyFilters)
388 return legacyDirFilters.testAnyFlags(QDir::AllDirs | QDir::Hidden);
389 return iteratorFlags.testAnyFlags(QDirListing::IteratorFlag::IncludeHidden);
391 if (!includeHidden && entryInfo.isHidden())
395 if (!entryInfo.isDir())
398 pushDirectory(entryInfo);
410 const QString &fileName = entryInfo.fileName();
411 if (fileName.isEmpty())
414 auto &filters = legacyDirFilters;
417 const bool dotOrDotDot = isDotOrDotDot(fileName);
418 const qsizetype fileNameSize = fileName.size();
419 if ((filters & QDir::NoDot) && dotOrDotDot && fileNameSize == 1)
421 if ((filters & QDir::NoDotDot) && dotOrDotDot && fileNameSize == 2)
425#if QT_CONFIG(regularexpression)
427 if (!(filters.testAnyFlags(QDir::AllDirs) && entryInfo.isDir())) {
428 if (!regexMatchesName(fileName))
433 const bool skipSymlinks = filters.testAnyFlag(QDir::NoSymLinks);
434 const bool includeSystem = filters.testAnyFlag(QDir::System);
435 if (skipSymlinks && entryInfo.isSymLink()) {
437 if (!includeSystem || entryInfo.exists())
442 const bool includeHidden = filters.testAnyFlag(QDir::Hidden);
443 if (!includeHidden && !dotOrDotDot && entryInfo.isHidden())
447 if (!includeSystem) {
448 if (!entryInfo.isFile() && !entryInfo.isDir() && !entryInfo.isSymLink())
450 if (entryInfo.isSymLink() && !entryInfo.exists())
455 const bool skipDirs = !(filters & (QDir::Dirs | QDir::AllDirs));
456 if (skipDirs && entryInfo.isDir())
460 const bool skipFiles = !(filters & QDir::Files);
461 if (skipFiles && entryInfo.isFile())
466 const auto perms = filters & QDir::PermissionMask;
467 const bool filterPermissions = perms != 0 && perms != QDir::PermissionMask;
468 if (filterPermissions) {
469 const bool doWritable = filters.testAnyFlags(QDir::Writable);
470 const bool doExecutable = filters.testAnyFlags(QDir::Executable);
471 const bool doReadable = filters.testAnyFlags(QDir::Readable);
472 if ((doReadable && !entryInfo.isReadable())
473 || (doWritable && !entryInfo.isWritable())
474 || (doExecutable && !entryInfo.isExecutable())) {
493 const QString &fileName = entryInfo.fileName();
494 if (fileName.isEmpty())
497 if (isDotOrDotDot(fileName))
498 return iteratorFlags.testAnyFlags(F::IncludeDotAndDotDot);
501#if QT_CONFIG(regularexpression)
502 if (!regexMatchesName(fileName))
506 if (!iteratorFlags.testAnyFlag(F::IncludeHidden) && entryInfo.isHidden())
509 if (entryInfo.isSymLink()) {
512 if (iteratorFlags.testAnyFlag(F::ResolveSymlinks)) {
513 if (!entryInfo.exists())
515 }
else if (iteratorFlags.testAnyFlags(F::FilesOnly)
516 || iteratorFlags.testAnyFlags(F::DirsOnly)) {
521 if (iteratorFlags.testAnyFlag(F::ExcludeSpecial)
522 && !entryInfo.isFile() && !entryInfo.isDir() && !entryInfo.isSymLink()) {
526 if (iteratorFlags.testAnyFlags(F::ExcludeDirs) && entryInfo.isDir())
529 if (iteratorFlags.testAnyFlags(F::ExcludeFiles) && entryInfo.isFile())
Q_CORE_EXPORT bool isReadable() const
Q_CORE_EXPORT bool isHidden() const
Q_CORE_EXPORT bool isWritable() const
Q_CORE_EXPORT bool isExecutable() const
Q_CORE_EXPORT bool isFile() const
Q_CORE_EXPORT bool exists() const
Q_CORE_EXPORT bool isSymLink() const
Q_CORE_EXPORT bool isDir() const