Backport of [1]+[2] to fix tests with Qt6.8.0 and build with Qt6.8.1. There was some refactoring in these files which prevent anything from applying cleanly, so this was manually rebased -- hopefully correct (fsengine tests pass again, so it should be fine). [1] https://github.com/qt-creator/qt-creator/commit/81d4e8a3742 [2] https://github.com/qt-creator/qt-creator/commit/f993fb76ded --- a/src/libs/utils/fsengine/diriterator.h +++ b/src/libs/utils/fsengine/diriterator.h @@ -16,4 +16,36 @@ namespace Internal { +#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) +inline std::pair convertQDirListingIteratorFlags( + QDirListing::IteratorFlags flags) +{ + QDir::Filters filters = QDir::Files | QDir::Dirs | QDir::System | QDir::NoDotAndDotDot; + QDirIterator::IteratorFlags iteratorFlags = QDirIterator::NoIteratorFlags; + + if (flags & QDirListing::IteratorFlag::ExcludeFiles) + filters.setFlag(QDir::Files, false); + if (flags & QDirListing::IteratorFlag::ExcludeDirs) + filters.setFlag(QDir::Dirs, false); + if (flags & QDirListing::IteratorFlag::ExcludeSpecial) + filters.setFlag(QDir::System, false); + if (flags & QDirListing::IteratorFlag::CaseSensitive) + filters.setFlag(QDir::CaseSensitive, true); + if (flags & QDirListing::IteratorFlag::IncludeHidden) + filters.setFlag(QDir::Hidden, true); + + if (flags & QDirListing::IteratorFlag::IncludeDotAndDotDot) { + filters.setFlag(QDir::NoDot, false); + filters.setFlag(QDir::NoDotDot, false); + } + + if (flags & QDirListing::IteratorFlag::Recursive) + iteratorFlags.setFlag(QDirIterator::Subdirectories, true); + if (flags & QDirListing::IteratorFlag::FollowDirSymlinks) + iteratorFlags.setFlag(QDirIterator::FollowSymlinks, true); + + return {filters, iteratorFlags}; +} +#endif + class DirIterator : public QAbstractFileEngineIterator { --- a/src/libs/utils/fsengine/fixedlistfsengine.h +++ b/src/libs/utils/fsengine/fixedlistfsengine.h @@ -67,8 +67,14 @@ #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) - IteratorUniquePtr beginEntryList(const QString &path, - QDir::Filters filters, - const QStringList &filterNames) override + QAbstractFileEngine::IteratorUniquePtr beginEntryList( + const QString &path, + QDirListing::IteratorFlags itFlags, + const QStringList &filterNames) override { + // We do not support recursive or following symlinks for the Fixed List engine. + Q_ASSERT(itFlags.testFlag(QDirListing::IteratorFlag::Recursive) == false); + + const auto [filters, _] = convertQDirListingIteratorFlags(itFlags); + return std::make_unique(m_children, path, filters, filterNames); } --- a/src/libs/utils/fsengine/fsengine_impl.cpp +++ b/src/libs/utils/fsengine/fsengine_impl.cpp @@ -297,11 +297,25 @@ #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) -QAbstractFileEngine::IteratorUniquePtr FSEngineImpl::beginEntryList(const QString &path, - QDir::Filters filters, - const QStringList &filterNames) +QAbstractFileEngine::IteratorUniquePtr FSEngineImpl::beginEntryList( + const QString &path, QDirListing::IteratorFlags itFlags, const QStringList &filterNames) +{ + const auto [filters, iteratorFlags] = convertQDirListingIteratorFlags(itFlags); + + FilePaths paths{m_filePath.pathAppended(".")}; + m_filePath.iterateDirectory( + [&paths](const FilePath &p, const FilePathInfo &fi) { + paths.append(p); + FilePathInfoCache::CachedData *data + = new FilePathInfoCache::CachedData{fi, QDateTime::currentDateTime().addSecs(60)}; + g_filePathInfoCache.cache(p, data); + return IterationPolicy::Continue; + }, + {filterNames, filters, iteratorFlags}); + + return std::make_unique(std::move(paths), path, filters, filterNames); +} #else QAbstractFileEngine::Iterator *FSEngineImpl::beginEntryList(QDir::Filters filters, const QStringList &filterNames) -#endif { FilePaths paths{m_filePath.pathAppended(".")}; @@ -317,10 +331,7 @@ {filterNames, filters}); -#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) - return std::make_unique(std::move(paths), path, filters, filterNames); -#else return new DirIterator(std::move(paths)); -#endif } +#endif qint64 FSEngineImpl::read(char *data, qint64 maxlen) --- a/src/libs/utils/fsengine/fsengine_impl.h +++ b/src/libs/utils/fsengine/fsengine_impl.h @@ -60,7 +60,10 @@ #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) - IteratorUniquePtr beginEntryList(const QString &path, QDir::Filters filters, - const QStringList &filterNames) override; - IteratorUniquePtr endEntryList() override { return {}; } + IteratorUniquePtr beginEntryList( + const QString &path, + QDirListing::IteratorFlags filters, + const QStringList &filterNames) final; + + IteratorUniquePtr endEntryList() final { return {}; } #else Iterator *beginEntryList(QDir::Filters filters, const QStringList &filterNames) override; --- a/src/libs/utils/fsengine/fsenginehandler.cpp +++ b/src/libs/utils/fsengine/fsenginehandler.cpp @@ -23,7 +23,8 @@ public: #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0) - IteratorUniquePtr beginEntryList(const QString &path, - QDir::Filters filters, - const QStringList &filterNames) override + IteratorUniquePtr beginEntryList( + const QString &path, + QDirListing::IteratorFlags filters, + const QStringList &filterNames) override { return std::make_unique(