forked from qt-creator/qt-creator
Docker: Implement fallback for DockerDevice::directoryEntries()
Change-Id: I57430bc4cf79abfc07ccbe06746a0857e10053da Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -969,7 +969,7 @@ bool FilePath::createDir() const
|
|||||||
return dir.mkpath(dir.absolutePath());
|
return dir.mkpath(dir.absolutePath());
|
||||||
}
|
}
|
||||||
|
|
||||||
QList<FilePath> FilePath::dirEntries(const QStringList &nameFilters,
|
FilePaths FilePath::dirEntries(const QStringList &nameFilters,
|
||||||
QDir::Filters filters,
|
QDir::Filters filters,
|
||||||
QDir::SortFlags sort) const
|
QDir::SortFlags sort) const
|
||||||
{
|
{
|
||||||
@@ -982,6 +982,41 @@ QList<FilePath> 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
|
||||||
{
|
{
|
||||||
return dirEntries({}, filters);
|
return dirEntries({}, filters);
|
||||||
|
@@ -227,6 +227,11 @@ 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);
|
||||||
|
@@ -1192,8 +1192,13 @@ FilePaths DockerDevice::directoryEntries(const FilePath &filePath,
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QTC_CHECK(false); // FIXME: Implement
|
QtcProcess proc;
|
||||||
return {};
|
proc.setCommand({"ls", {"-1", "-b", "--", filePath.path()}});
|
||||||
|
runProcess(proc);
|
||||||
|
proc.waitForFinished();
|
||||||
|
|
||||||
|
QStringList entries = proc.stdOut().split('\n', Qt::SkipEmptyParts);
|
||||||
|
return FilePath::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