diff --git a/src/libs/utils/deviceshell.cpp b/src/libs/utils/deviceshell.cpp index 69abc5ce4a4..5f12c8ab829 100644 --- a/src/libs/utils/deviceshell.cpp +++ b/src/libs/utils/deviceshell.cpp @@ -162,7 +162,7 @@ CommandLine DeviceShell::createFallbackCommand(const CommandLine &cmd) * * \note You have to call this function when deriving from DeviceShell. Current implementations call the function from their constructor. */ -expected_str DeviceShell::start() +Result DeviceShell::start() { m_shellProcess = std::make_unique(); connect(m_shellProcess.get(), &Process::done, m_shellProcess.get(), @@ -250,11 +250,11 @@ expected_str DeviceShell::checkCommand(const QByteArray &command) return out; } -expected_str DeviceShell::installShellScript() +Result DeviceShell::installShellScript() { if (m_forceFailScriptInstallation) { m_shellScriptState = State::Failed; - return make_unexpected(Tr::tr("Script installation was forced to fail.")); + return Result::Error(Tr::tr("Script installation was forced to fail.")); } static const QList requiredCommands @@ -263,7 +263,7 @@ expected_str DeviceShell::installShellScript() for (const QByteArray &command : requiredCommands) { auto checkResult = checkCommand(command); if (!checkResult) - return make_unexpected(checkResult.error()); + return Result::Error(checkResult.error()); } const static QByteArray shellScriptBase64 = FilePath(":/utils/scripts/deviceshell.sh") @@ -279,18 +279,17 @@ expected_str DeviceShell::installShellScript() m_shellProcess->writeRaw(scriptCmd); while (m_shellScriptState == State::Unknown) { - if (!m_shellProcess->waitForReadyRead(5s)) { - return make_unexpected(Tr::tr("Timeout while waiting for shell script installation.")); - } + if (!m_shellProcess->waitForReadyRead(5s)) + return Result::Error(Tr::tr("Timeout while waiting for shell script installation.")); QByteArray out = m_shellProcess->readAllRawStandardError(); if (out.contains("SCRIPT_INSTALLED") && !out.contains("ERROR_INSTALL_SCRIPT")) { m_shellScriptState = State::Succeeded; - return {}; + return Result::Ok; } if (out.contains("ERROR_INSTALL_SCRIPT")) { m_shellScriptState = State::Failed; - return make_unexpected( + return Result::Error( Tr::tr("Failed to install shell script: %1").arg(QString::fromUtf8(out))); } if (!out.isEmpty()) { @@ -299,7 +298,7 @@ expected_str DeviceShell::installShellScript() } } - return {}; + return Result::Ok; } void DeviceShell::closeShellProcess() diff --git a/src/libs/utils/deviceshell.h b/src/libs/utils/deviceshell.h index 1bd1d36cd18..41aadc2624e 100644 --- a/src/libs/utils/deviceshell.h +++ b/src/libs/utils/deviceshell.h @@ -38,7 +38,7 @@ public: DeviceShell(bool forceFailScriptInstallation = false); virtual ~DeviceShell(); - expected_str start(); + Result start(); RunResult runInShell(const CommandLine &cmd, const QByteArray &stdInData = {}); @@ -58,7 +58,7 @@ private: virtual void setupShellProcess(Process *shellProcess); virtual CommandLine createFallbackCommand(const CommandLine &cmdLine); - expected_str installShellScript(); + Result installShellScript(); void closeShellProcess(); void onReadyRead(); diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 2c028034eb1..534e7740491 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -311,7 +311,7 @@ public: explicit LinuxDevicePrivate(LinuxDevice *parent); ~LinuxDevicePrivate(); - bool setupShell(const SshParameters &sshParameters, bool announce); + Result setupShell(const SshParameters &sshParameters, bool announce); RunResult runInShell(const CommandLine &cmd, const QByteArray &stdInData = {}); void announceConnectionAttempt(); void unannounceConnectionAttempt(); @@ -896,7 +896,7 @@ public: } // Call me with shell mutex locked - bool start(const SshParameters ¶meters) + Result start(const SshParameters ¶meters) { closeShell(); setSshParameters(parameters); @@ -913,12 +913,12 @@ public: connect(m_shell.get(), &DeviceShell::done, this, [this] { closeShell(); }); - auto result = m_shell->start(); + Result result = m_shell->start(); if (!result) { qCWarning(linuxDeviceLog) << "Failed to start shell for:" << parameters.userAtHostAndPort() << ", " << result.error(); } - return result.has_value(); + return result; } // Call me with shell mutex locked @@ -1186,11 +1186,11 @@ void LinuxDevicePrivate::checkOsType() } // Call me with shell mutex locked -bool LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool announce) +Result LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool announce) { if (m_handler->isRunning(sshParameters)) { setDisconnected(false); - return true; + return Result::Ok; } invalidateEnvironmentCache(); @@ -1198,22 +1198,22 @@ bool LinuxDevicePrivate::setupShell(const SshParameters &sshParameters, bool ann if (announce) announceConnectionAttempt(); - bool ok = false; + Result result = Result::Error("setupShell failed"); QMetaObject::invokeMethod(m_handler, [this, sshParameters] { return m_handler->start(sshParameters); - }, Qt::BlockingQueuedConnection, &ok); + }, Qt::BlockingQueuedConnection, &result); if (announce) unannounceConnectionAttempt(); - if (ok) { + if (result) { setDisconnected(false); queryOsType([this](const CommandLine &cmd) { return m_handler->runInShell(cmd); }); } else { setDisconnected(true); } - return ok; + return result; } RunResult LinuxDevicePrivate::runInShell(const CommandLine &cmd, const QByteArray &data)