From ff5351b12f4dd6de1a96728859456aac556272af Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 8 Jul 2025 13:45:52 -0700 Subject: QDirListing: check the flags before calling isSymLink() This delays potentially expensive FS checks until we know we need them. Task-number: QTBUG-138374 Fixes: QTBUG-134740 Pick-to: 6.10 6.9 6.8 Change-Id: I4a2f6e8c3713cc0033d7fffd5c75676be4e7e541 Reviewed-by: Ahmad Samir Reviewed-by: Fabian Kosmale --- src/corelib/io/qdirlisting.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/corelib/io/qdirlisting.cpp b/src/corelib/io/qdirlisting.cpp index c626033dcdb..1fec92a01e2 100644 --- a/src/corelib/io/qdirlisting.cpp +++ b/src/corelib/io/qdirlisting.cpp @@ -510,16 +510,14 @@ bool QDirListingPrivate::matchesFilters(QDirEntryInfo &entryInfo) const if (!iteratorFlags.testAnyFlag(F::IncludeHidden) && entryInfo.isHidden()) return false; - if (entryInfo.isSymLink()) { - // With ResolveSymlinks, we look at the type of the link's target, - // and exclude broken symlinks (where the target doesn't exist). - if (iteratorFlags.testAnyFlag(F::ResolveSymlinks)) { - if (!entryInfo.exists()) - return false; - } else if (iteratorFlags.testAnyFlags(F::FilesOnly) - || iteratorFlags.testAnyFlags(F::DirsOnly)) { - return false; // symlink is not a file or dir - } + // With ResolveSymlinks, we look at the type of the link's target, + // and exclude broken symlinks (where the target doesn't exist). + if (iteratorFlags.testAnyFlag(F::ResolveSymlinks)) { + if (entryInfo.isSymLink() && !entryInfo.exists()) + return false; + } else if ((iteratorFlags.testAnyFlags(F::FilesOnly) + || iteratorFlags.testAnyFlags(F::DirsOnly)) && entryInfo.isSymLink()) { + return false; // symlink is not a file or dir } if (iteratorFlags.testAnyFlag(F::ExcludeOther) -- cgit v1.2.3