Docker: Improve iterateWithFind

Handle critical file pattern after we got the results from find
to avoid finding to many false positives.
File patterns like "lldb-[1-9]*" end up using "lldb-?*" inside
find and will basically find anything starting with "lldb-"
which includes lots of additional lldb tools that cannot be
used as debugger at all and slows down the detection unnecessarily.

Change-Id: I0c816ae6b6e472b710ffede532c97c55a9d698fa
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Christian Stenger
2022-01-24 10:01:37 +01:00
parent cfae24a6e5
commit 22dd26bc76

View File

@@ -1484,13 +1484,17 @@ void DockerDevice::iterateWithFind(const FilePath &filePath,
const QString nameOption = (filters & QDir::CaseSensitive) ? QString{"-name"}
: QString{"-iname"};
QStringList criticalWildcards;
if (!nameFilters.isEmpty()) {
filterOptions << nameOption << nameFilters.first();
const QRegularExpression oneChar("\\[.*?\\]");
for (int i = 1, len = nameFilters.size(); i < len; ++i) {
for (int i = 0, len = nameFilters.size(); i < len; ++i) {
if (i > 0)
filterOptions << "-o";
QString current = nameFilters.at(i);
if (current.indexOf(oneChar) != -1)
criticalWildcards.append(current);
current.replace(oneChar, "?"); // BAD! but still better than nothing
filterOptions << "-o" << nameOption << current;
filterOptions << nameOption << current;
}
}
arguments << filterOptions;
@@ -1505,7 +1509,19 @@ void DockerDevice::iterateWithFind(const FilePath &filePath,
for (const QString &entry : entries) {
if (entry.startsWith("find: "))
continue;
if (!callBack(FilePath::fromString(entry).onDevice(filePath)))
const FilePath fp = FilePath::fromString(entry);
if (!Utils::anyOf(criticalWildcards,
[name = fp.fileName()](const QString &pattern) {
const QRegularExpression regex(QRegularExpression::wildcardToRegularExpression(pattern));
if (regex.match(name).hasMatch())
return true;
return false;
})) {
continue;
}
if (!callBack(fp.onDevice(filePath)))
break;
}
}