forked from qt-creator/qt-creator
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 <hjk@qt.io>
This commit is contained in:
@@ -710,40 +710,6 @@ FilePaths FilePath::dirEntries(const QStringList &nameFilters,
|
|||||||
return Utils::transform(entryInfoList, &FilePath::fromFileInfo);
|
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<QRegularExpression> 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> FilePath::dirEntries(QDir::Filters filters) const
|
QList<FilePath> FilePath::dirEntries(QDir::Filters filters) const
|
||||||
{
|
{
|
||||||
|
@@ -173,11 +173,6 @@ public:
|
|||||||
static void removeDuplicates(QList<FilePath> &files);
|
static void removeDuplicates(QList<FilePath> &files);
|
||||||
static void sort(QList<FilePath> &files);
|
static void sort(QList<FilePath> &files);
|
||||||
|
|
||||||
static QList<FilePath> filterEntriesHelper(const FilePath &base,
|
|
||||||
const QStringList &entries,
|
|
||||||
const QStringList &nameFilters,
|
|
||||||
QDir::Filters filters,
|
|
||||||
QDir::SortFlags sort);
|
|
||||||
private:
|
private:
|
||||||
friend class ::tst_fileutils;
|
friend class ::tst_fileutils;
|
||||||
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);
|
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QOperatingSystemVersion>
|
#include <QOperatingSystemVersion>
|
||||||
#include <QRegularExpression>
|
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
#include <qplatformdefs.h>
|
#include <qplatformdefs.h>
|
||||||
|
@@ -70,6 +70,7 @@
|
|||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QRandomGenerator>
|
#include <QRandomGenerator>
|
||||||
|
#include <QRegularExpression>
|
||||||
#include <QTextBrowser>
|
#include <QTextBrowser>
|
||||||
#include <QToolButton>
|
#include <QToolButton>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
@@ -1274,6 +1275,41 @@ FilePath DockerDevice::symLinkTarget(const FilePath &filePath) const
|
|||||||
return output.isEmpty() ? FilePath() : filePath.withNewPath(output);
|
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<QRegularExpression> 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,
|
FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
||||||
const QStringList &nameFilters,
|
const QStringList &nameFilters,
|
||||||
QDir::Filters filters,
|
QDir::Filters filters,
|
||||||
@@ -1290,7 +1326,7 @@ FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
|||||||
|
|
||||||
const QString output = d->outputForRunInShell({"ls", {"-1", "-b", "--", filePath.path()}});
|
const QString output = d->outputForRunInShell({"ls", {"-1", "-b", "--", filePath.path()}});
|
||||||
QStringList entries = output.split('\n', Qt::SkipEmptyParts);
|
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
|
QByteArray DockerDevice::fileContents(const FilePath &filePath, qint64 limit, qint64 offset) const
|
||||||
|
Reference in New Issue
Block a user