From 441488dd5204e8a9bb753befbc8e837b50523f23 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 4 May 2022 11:10:57 +0200 Subject: [PATCH] Docker: fix find arguments, support outputForRunInShell called from non-main thread * Added -mindepth 1 to not return the directory that is being searched in. * Added parenthesis around -type options to correctly express that files OR directories should be searched, without affecting the following parameters. * Added parenthesis around -readable, -writeable and -executable and added -o between them, to correctly indicate that any of the selected type should be searched for. Change-Id: Ibc77a2a99826663b88015e8f43b5664563384127 Reviewed-by: Jarek Kobus Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 47 ++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 11 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 35cd37b7351..140c00f7f32 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -883,24 +883,43 @@ void DockerDevice::iterateWithFind(const FilePath &filePath, else arguments.prepend("-L"); + arguments.append({"-mindepth", "1"}); + if (!filter.iteratorFlags.testFlag(QDirIterator::Subdirectories)) arguments.append({"-maxdepth", "1"}); QStringList filterOptions; + + if (!(filters & QDir::Hidden)) + filterOptions << "!" << "-name" << ".*"; + + QStringList filterFilesAndDirs; if (filters & QDir::Dirs) - filterOptions << "-type" << "d"; + filterFilesAndDirs << "-type" << "d"; if (filters & QDir::Files) { - if (!filterOptions.isEmpty()) - filterOptions << "-o"; - filterOptions << "-type" << "f"; + if (!filterFilesAndDirs.isEmpty()) + filterFilesAndDirs << "-o"; + filterFilesAndDirs << "-type" << "f"; + } + if (!filterFilesAndDirs.isEmpty()) + filterOptions << "(" << filterFilesAndDirs << ")"; + + QStringList accessOptions; + if (filters & QDir::Readable) + accessOptions << "-readable"; + if (filters & QDir::Writable) { + if (!accessOptions.isEmpty()) + accessOptions << "-o"; + accessOptions << "-writable"; + } + if (filters & QDir::Executable) { + if (!accessOptions.isEmpty()) + accessOptions << "-o"; + accessOptions << "-executable"; } - if (filters & QDir::Readable) - filterOptions << "-readable"; - if (filters & QDir::Writable) - filterOptions << "-writable"; - if (filters & QDir::Executable) - filterOptions << "-executable"; + if (!accessOptions.isEmpty()) + filterOptions << "(" << accessOptions << ")"; QTC_CHECK(filters ^ QDir::AllDirs); QTC_CHECK(filters ^ QDir::Drives); @@ -1109,7 +1128,13 @@ static QByteArray randomHex() QByteArray DockerDevicePrivate::outputForRunInShell(const CommandLine &cmd) const { - QTC_ASSERT(QThread::currentThread() == qApp->thread(), return {}); + if (QThread::currentThread() != qApp->thread()) { + QByteArray result; + QMetaObject::invokeMethod(const_cast(this), [this, &cmd, &result] { + result = this->outputForRunInShell(cmd); + }, Qt::BlockingQueuedConnection); + return result; + } if (!DockerApi::isDockerDaemonAvailable(false).value_or(false)) return {};