From 34dc092642fcc62662e438afeb95d7af98c8a9af Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 29 Sep 2022 15:03:29 +0200 Subject: [PATCH] Docker: Improve File contents read speed Change-Id: Ic94715d2c362ac3aa75dabf4f95c74737abd6264 Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 44 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index a28147c688c..2abd9ed946e 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -128,6 +128,8 @@ public: bool runInShell(const CommandLine &cmd, const QByteArray &stdInData = {}); QByteArray outputForRunInShell(const CommandLine &cmd); + std::optional fileContents(const FilePath &filePath, qint64 limit, qint64 offset); + void updateContainerAccess(); void changeMounts(QStringList newMounts); bool ensureReachable(const FilePath &other); @@ -1010,25 +1012,7 @@ std::optional DockerDevice::fileContents(const FilePath &filePath, qint64 offset) const { QTC_ASSERT(handlesFile(filePath), return {}); - updateContainerAccess(); - - QStringList args = {"if=" + filePath.path(), "status=none"}; - if (limit > 0 || offset > 0) { - const qint64 gcd = std::gcd(limit, offset); - args += {QString("bs=%1").arg(gcd), - QString("count=%1").arg(limit / gcd), - QString("seek=%1").arg(offset / gcd)}; - } - - QtcProcess proc; - proc.setCommand(d->withDockerExecCmd({"dd", args})); - proc.start(); - proc.waitForFinished(); - - if (proc.result() != ProcessResult::FinishedWithSuccess) - return {}; - QByteArray output = proc.readAllStandardOutput(); - return output; + return d->fileContents(filePath, limit, offset); } bool DockerDevice::writeFileContents(const FilePath &filePath, const QByteArray &data) const @@ -1048,6 +1032,28 @@ void DockerDevice::aboutToBeRemoved() const detector.undoAutoDetect(id().toString()); } +std::optional DockerDevicePrivate::fileContents(const FilePath &filePath, + qint64 limit, + qint64 offset) +{ + updateContainerAccess(); + + QStringList args = {"if=" + filePath.path(), "status=none"}; + if (limit > 0 || offset > 0) { + const qint64 gcd = std::gcd(limit, offset); + args += {QString("bs=%1").arg(gcd), + QString("count=%1").arg(limit / gcd), + QString("seek=%1").arg(offset / gcd)}; + } + + const ContainerShell::RunResult r = m_shell->outputForRunInShell({"dd", args}); + + if (r.exitCode != 0) + return {}; + + return r.stdOut; +} + void DockerDevicePrivate::fetchSystemEnviroment() { updateContainerAccess();