forked from qt-creator/qt-creator
ProjectExplorer: filepathify recursive scan for files
This allows using the scanner on remote paths and avoids some unneeded FilePath::fromString and FilePath::toString calls. Change-Id: I4871613a9d36daf78607b196f4dfb6e165be8305 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -24,42 +24,38 @@ QList<FileNode *> scanForFilesRecursively(
|
|||||||
const Utils::FilePath &directory,
|
const Utils::FilePath &directory,
|
||||||
const QDir::Filters &filter,
|
const QDir::Filters &filter,
|
||||||
const std::function<FileNode *(const Utils::FilePath &)> factory,
|
const std::function<FileNode *(const Utils::FilePath &)> factory,
|
||||||
QSet<QString> &visited,
|
QSet<Utils::FilePath> &visited,
|
||||||
const QList<Core::IVersionControl *> &versionControls)
|
const QList<Core::IVersionControl *> &versionControls)
|
||||||
{
|
{
|
||||||
QList<FileNode *> result;
|
QList<FileNode *> result;
|
||||||
|
|
||||||
const QDir baseDir = QDir(directory.toString());
|
|
||||||
|
|
||||||
// Do not follow directory loops:
|
// Do not follow directory loops:
|
||||||
const int visitedCount = visited.count();
|
if (!Utils::insert(visited, directory.canonicalPath()))
|
||||||
visited.insert(baseDir.canonicalPath());
|
|
||||||
if (visitedCount == visited.count())
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
const QFileInfoList entries = baseDir.entryInfoList(QStringList(), filter);
|
const Utils::FilePaths entries = directory.dirEntries(filter);
|
||||||
double progress = 0;
|
double progress = 0;
|
||||||
const double progressIncrement = progressRange / static_cast<double>(entries.count());
|
const double progressIncrement = progressRange / static_cast<double>(entries.count());
|
||||||
int lastIntProgress = 0;
|
int lastIntProgress = 0;
|
||||||
for (const QFileInfo &entry : entries) {
|
for (const Utils::FilePath &entry : entries) {
|
||||||
if (promise.isCanceled())
|
if (promise.isCanceled())
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
const Utils::FilePath entryName = Utils::FilePath::fromString(entry.absoluteFilePath());
|
if (!Utils::contains(versionControls, [entry](const Core::IVersionControl *vc) {
|
||||||
if (!Utils::contains(versionControls, [&entryName](const Core::IVersionControl *vc) {
|
return vc->isVcsFileOrDirectory(entry);
|
||||||
return vc->isVcsFileOrDirectory(entryName);
|
|
||||||
})) {
|
})) {
|
||||||
if (entry.isDir())
|
if (entry.isDir()) {
|
||||||
result.append(scanForFilesRecursively(promise,
|
result.append(scanForFilesRecursively(promise,
|
||||||
progress,
|
progress,
|
||||||
progressIncrement,
|
progressIncrement,
|
||||||
entryName,
|
entry,
|
||||||
filter,
|
filter,
|
||||||
factory,
|
factory,
|
||||||
visited,
|
visited,
|
||||||
versionControls));
|
versionControls));
|
||||||
else if (FileNode *node = factory(entryName))
|
} else if (FileNode *node = factory(entry)) {
|
||||||
result.append(node);
|
result.append(node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
progress += progressIncrement;
|
progress += progressIncrement;
|
||||||
const int intProgress = std::min(static_cast<int>(progressStart + progress),
|
const int intProgress = std::min(static_cast<int>(progressStart + progress),
|
||||||
@@ -82,7 +78,7 @@ QList<FileNode *> scanForFiles(
|
|||||||
const QDir::Filters &filter,
|
const QDir::Filters &filter,
|
||||||
const std::function<FileNode *(const Utils::FilePath &)> factory)
|
const std::function<FileNode *(const Utils::FilePath &)> factory)
|
||||||
{
|
{
|
||||||
QSet<QString> visited;
|
QSet<Utils::FilePath> visited;
|
||||||
promise.setProgressRange(0, 1000000);
|
promise.setProgressRange(0, 1000000);
|
||||||
return Internal::scanForFilesRecursively(promise,
|
return Internal::scanForFilesRecursively(promise,
|
||||||
0.0,
|
0.0,
|
||||||
|
Reference in New Issue
Block a user