forked from qt-creator/qt-creator
Utils: Use Result instead expected_str<void> in some places
Change-Id: Iac691355ea51fc03d275606a2111074d898be58d Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -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<void> DeviceShell::start()
|
||||
Result DeviceShell::start()
|
||||
{
|
||||
m_shellProcess = std::make_unique<Process>();
|
||||
connect(m_shellProcess.get(), &Process::done, m_shellProcess.get(),
|
||||
@@ -250,11 +250,11 @@ expected_str<QByteArray> DeviceShell::checkCommand(const QByteArray &command)
|
||||
return out;
|
||||
}
|
||||
|
||||
expected_str<void> 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<QByteArray> requiredCommands
|
||||
@@ -263,7 +263,7 @@ expected_str<void> 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<void> 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<void> DeviceShell::installShellScript()
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
return Result::Ok;
|
||||
}
|
||||
|
||||
void DeviceShell::closeShellProcess()
|
||||
|
@@ -38,7 +38,7 @@ public:
|
||||
DeviceShell(bool forceFailScriptInstallation = false);
|
||||
virtual ~DeviceShell();
|
||||
|
||||
expected_str<void> 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<void> installShellScript();
|
||||
Result installShellScript();
|
||||
void closeShellProcess();
|
||||
|
||||
void onReadyRead();
|
||||
|
@@ -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)
|
||||
|
Reference in New Issue
Block a user