forked from qt-creator/qt-creator
Utils: Implement ls-based subdir iteration
Needed when 'find' does not work as expected. Change-Id: Ifbe762590ad2a6339152ed728e4d72820b4eae91 Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io> Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -648,6 +648,24 @@ static bool iterateWithFind(const FilePath &filePath,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void findUsingLs(const QString ¤t,
|
||||||
|
const FileFilter &filter,
|
||||||
|
const std::function<RunResult(const CommandLine &)> &runInShell,
|
||||||
|
QStringList *found)
|
||||||
|
{
|
||||||
|
const RunResult result = runInShell({"ls", {"-1", "-p", "--", current}});
|
||||||
|
const QStringList entries = QString::fromUtf8(result.stdOut).split('\n', Qt::SkipEmptyParts);
|
||||||
|
for (QString entry : entries) {
|
||||||
|
const QChar last = entry.back();
|
||||||
|
if (last == '/') {
|
||||||
|
entry.chop(1);
|
||||||
|
if (filter.iteratorFlags.testFlag(QDirIterator::Subdirectories))
|
||||||
|
findUsingLs(current + '/' + entry, filter, runInShell, found);
|
||||||
|
}
|
||||||
|
found->append(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FileUtils::iterateUnixDirectory(const FilePath &filePath,
|
void FileUtils::iterateUnixDirectory(const FilePath &filePath,
|
||||||
const FileFilter &filter,
|
const FileFilter &filter,
|
||||||
bool *useFind,
|
bool *useFind,
|
||||||
@@ -665,9 +683,8 @@ void FileUtils::iterateUnixDirectory(const FilePath &filePath,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we do not have find - use ls as fallback
|
// if we do not have find - use ls as fallback
|
||||||
// FIXME: Recursion into subdirectories not implemented!
|
QStringList entries;
|
||||||
const RunResult result = runInShell({"ls", {"-1", "-b", "--", filePath.path()}});
|
findUsingLs(filePath.path(), filter, runInShell, &entries);
|
||||||
const QStringList entries = QString::fromUtf8(result.stdOut).split('\n', Qt::SkipEmptyParts);
|
|
||||||
FileUtils::iterateLsOutput(filePath, entries, filter, callBack);
|
FileUtils::iterateLsOutput(filePath, entries, filter, callBack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user