From a0da3ce69fc371eb86ba9740cf0c56179eea1c4e Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Thu, 22 Jul 2021 14:08:53 +0200 Subject: [PATCH] Utils: Move filterEntriesHelper() out of FilePath Currently only used inside DockerDevice and it fails to build when building sdktool with old Qt which is still necessary. Change-Id: Ic48414f0cb8f0955e7561f7484e3ea1c726c816a Reviewed-by: hjk --- src/libs/utils/filepath.cpp | 34 -------------------------- src/libs/utils/filepath.h | 5 ---- src/libs/utils/fileutils.cpp | 1 - src/plugins/docker/dockerdevice.cpp | 38 ++++++++++++++++++++++++++++- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index eda575945ae..a5264d17987 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -710,40 +710,6 @@ FilePaths FilePath::dirEntries(const QStringList &nameFilters, return Utils::transform(entryInfoList, &FilePath::fromFileInfo); } -FilePaths FilePath::filterEntriesHelper(const FilePath &base, - const QStringList &entries, - const QStringList &nameFilters, - QDir::Filters filters, - QDir::SortFlags sort) -{ - const QList nameRegexps = transform(nameFilters, [](const QString &filter) { - QRegularExpression re; - re.setPattern(QRegularExpression::wildcardToRegularExpression(filter)); - QTC_CHECK(re.isValid()); - return re; - }); - - const auto nameMatches = [&nameRegexps](const QString &fileName) { - for (const QRegularExpression &re : nameRegexps) { - const QRegularExpressionMatch match = re.match(fileName); - if (match.hasMatch()) - return true; - } - return false; - }; - - // FIXME: Handle sort and filters. For now bark on unsupported options. - QTC_CHECK(filters == QDir::NoFilter); - QTC_CHECK(sort == QDir::NoSort); - - FilePaths result; - for (const QString &entry : entries) { - if (!nameMatches(entry)) - continue; - result.append(base.pathAppended(entry)); - } - return result; -} QList FilePath::dirEntries(QDir::Filters filters) const { diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index d53357057db..6ece9ea162a 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -173,11 +173,6 @@ public: static void removeDuplicates(QList &files); static void sort(QList &files); - static QList filterEntriesHelper(const FilePath &base, - const QStringList &entries, - const QStringList &nameFilters, - QDir::Filters filters, - QDir::SortFlags sort); private: friend class ::tst_fileutils; static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 54f3c1ddf7b..ff7745761c8 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index eb0508d4b2c..bacbc36204c 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -70,6 +70,7 @@ #include #include #include +#include #include #include #include @@ -1274,6 +1275,41 @@ FilePath DockerDevice::symLinkTarget(const FilePath &filePath) const return output.isEmpty() ? FilePath() : filePath.withNewPath(output); } +static FilePaths filterEntriesHelper(const FilePath &base, + const QStringList &entries, + const QStringList &nameFilters, + QDir::Filters filters, + QDir::SortFlags sort) +{ + const QList nameRegexps = transform(nameFilters, [](const QString &filter) { + QRegularExpression re; + re.setPattern(QRegularExpression::wildcardToRegularExpression(filter)); + QTC_CHECK(re.isValid()); + return re; + }); + + const auto nameMatches = [&nameRegexps](const QString &fileName) { + for (const QRegularExpression &re : nameRegexps) { + const QRegularExpressionMatch match = re.match(fileName); + if (match.hasMatch()) + return true; + } + return false; + }; + + // FIXME: Handle sort and filters. For now bark on unsupported options. + QTC_CHECK(filters == QDir::NoFilter); + QTC_CHECK(sort == QDir::NoSort); + + FilePaths result; + for (const QString &entry : entries) { + if (!nameMatches(entry)) + continue; + result.append(base.pathAppended(entry)); + } + return result; +} + FilePaths DockerDevice::directoryEntries(const FilePath &filePath, const QStringList &nameFilters, QDir::Filters filters, @@ -1290,7 +1326,7 @@ FilePaths DockerDevice::directoryEntries(const FilePath &filePath, const QString output = d->outputForRunInShell({"ls", {"-1", "-b", "--", filePath.path()}}); QStringList entries = output.split('\n', Qt::SkipEmptyParts); - return FilePath::filterEntriesHelper(filePath, entries, nameFilters, filters, sort); + return filterEntriesHelper(filePath, entries, nameFilters, filters, sort); } QByteArray DockerDevice::fileContents(const FilePath &filePath, qint64 limit, qint64 offset) const