Docker: Improve DockerApi::canConnect

Replaced Process::start with Process::runBlocking and some
general cleanup.

Change-Id: I5e2be010b4e6d799d586dbbcd86ca5bf64294ccb
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2025-02-18 13:34:04 +01:00
parent 881f15da6b
commit e5a3566362

View File

@@ -38,22 +38,19 @@ bool DockerApi::canConnect()
{
Process process;
FilePath dockerExe = dockerClient();
if (dockerExe.isEmpty() || !dockerExe.isExecutableFile())
if (dockerExe.isEmpty())
return false;
bool result = false;
process.setCommand({dockerExe, {"info"}});
connect(&process, &Process::done, [&process, &result] {
process.runBlocking();
const bool success = process.result() == ProcessResult::FinishedWithSuccess;
if (!success)
qCWarning(dockerApiLog) << "Failed to connect to docker daemon:" << process.allOutput();
else
qCInfo(dockerApiLog) << "'docker info' result:\n" << qPrintable(process.allOutput());
if (process.result() == ProcessResult::FinishedWithSuccess)
result = true;
});
process.start();
process.waitForFinished();
return result;
return process.result() == ProcessResult::FinishedWithSuccess;
}
bool DockerApi::isContainerRunning(const QString &containerId)