From f0540f8392dc49c63908a196b71c1c4ae6607599 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 1 Dec 2022 10:24:42 +0100 Subject: [PATCH] Docker: Convert isValidMountInfo to expected Change-Id: I582939990f85c1dc3eed474b3bac0e6b4efe3367 Reviewed-by: hjk --- src/plugins/docker/dockerdevice.cpp | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index fc76471b1eb..ad962e9641e 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -542,23 +543,37 @@ QStringList toMountArg(const DockerDevicePrivate::TemporaryMountInfo &mi) return QStringList{"--mount", mountArg}; } -bool isValidMountInfo(const DockerDevicePrivate::TemporaryMountInfo &mi) +expected_str isValidMountInfo(const DockerDevicePrivate::TemporaryMountInfo &mi) { if (mi.path.needsDevice()) - return false; + return make_unexpected(QString("Path \"%1\" is not local").arg(mi.path.toUserOutput())); - if (mi.path.isEmpty() || mi.containerPath.isEmpty()) - return false; - if (!mi.path.isAbsolutePath() || !mi.containerPath.isAbsolutePath()) - return false; + if (mi.path.isEmpty() && mi.containerPath.isEmpty()) + return make_unexpected(QString("Both paths are empty")); + + if (mi.path.isEmpty()) { + return make_unexpected(QString("Local path is empty, container path is \"%1\"") + .arg(mi.containerPath.toUserOutput())); + } + + if (mi.containerPath.isEmpty()) { + return make_unexpected( + QString("Container path is empty, local path is \"%1\"").arg(mi.path.toUserOutput())); + } + + if (!mi.path.isAbsolutePath() || !mi.containerPath.isAbsolutePath()) { + return make_unexpected(QString("Path \"%1\" or \"%2\" is not absolute") + .arg(mi.path.toUserOutput()) + .arg(mi.containerPath.toUserOutput())); + } if (mi.containerPath.isRootPath()) - return false; + return make_unexpected(QString("Path \"%1\" is root").arg(mi.containerPath.toUserOutput())); if (!mi.path.exists()) - return false; + return make_unexpected(QString("Path \"%1\" does not exist").arg(mi.path.toUserOutput())); - return true; + return {}; } QStringList DockerDevicePrivate::createMountArgs() const @@ -1098,7 +1113,8 @@ bool DockerDevicePrivate::addTemporaryMount(const FilePath &path, const FilePath const TemporaryMountInfo newMount{path, containerPath}; - QTC_ASSERT(isValidMountInfo(newMount), return false); + const expected_str result = isValidMountInfo(newMount); + QTC_ASSERT_EXPECTED(result, return false); qCDebug(dockerDeviceLog) << "Adding temporary mount:" << path; m_temporaryMounts.append(newMount);