forked from qt-creator/qt-creator
AbstractRemoteLinuxPackageInstaller: Don't use SshRemoteProcessRunner
Use QtcProcess with a path on device instead. Change-Id: Ia142645b25cd9e0512495642f454cb87ec54fd51 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -26,12 +26,14 @@
|
||||
#include "remotelinuxpackageinstaller.h"
|
||||
|
||||
#include <projectexplorer/devicesupport/idevice.h>
|
||||
#include <ssh/sshremoteprocessrunner.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/qtcprocess.h>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace QSsh;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
@@ -39,10 +41,9 @@ namespace Internal {
|
||||
class AbstractRemoteLinuxPackageInstallerPrivate
|
||||
{
|
||||
public:
|
||||
bool isRunning = false;
|
||||
IDevice::ConstPtr deviceConfig;
|
||||
SshRemoteProcessRunner *installer = nullptr;
|
||||
SshRemoteProcessRunner *killProcess = nullptr;
|
||||
IDevice::ConstPtr m_device;
|
||||
QtcProcess m_installer;
|
||||
QtcProcess m_killer;
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
@@ -50,89 +51,45 @@ public:
|
||||
AbstractRemoteLinuxPackageInstaller::AbstractRemoteLinuxPackageInstaller(QObject *parent)
|
||||
: QObject(parent), d(new Internal::AbstractRemoteLinuxPackageInstallerPrivate)
|
||||
{
|
||||
connect(&d->m_installer, &QtcProcess::readyReadStandardOutput, this, [this] {
|
||||
emit stdoutData(QString::fromUtf8(d->m_installer.readAllStandardOutput()));
|
||||
});
|
||||
connect(&d->m_installer, &QtcProcess::readyReadStandardError, this, [this] {
|
||||
emit stderrData(QString::fromUtf8(d->m_installer.readAllStandardError()));
|
||||
});
|
||||
connect(&d->m_installer, &QtcProcess::finished, this, [this] {
|
||||
const QString errorMessage = d->m_installer.result() == ProcessResult::FinishedWithSuccess
|
||||
? QString() : tr("Installing package failed.") + d->m_installer.errorString();
|
||||
emit finished(errorMessage);
|
||||
});
|
||||
}
|
||||
|
||||
AbstractRemoteLinuxPackageInstaller::~AbstractRemoteLinuxPackageInstaller()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
AbstractRemoteLinuxPackageInstaller::~AbstractRemoteLinuxPackageInstaller() = default;
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig,
|
||||
const QString &packageFilePath, bool removePackageFile)
|
||||
{
|
||||
QTC_ASSERT(!d->isRunning, return);
|
||||
QTC_ASSERT(d->m_installer.state() == QProcess::NotRunning, return);
|
||||
|
||||
d->deviceConfig = deviceConfig;
|
||||
prepareInstallation();
|
||||
if (!d->installer)
|
||||
d->installer = new SshRemoteProcessRunner(this);
|
||||
connect(d->installer, &SshRemoteProcessRunner::connectionError,
|
||||
this, &AbstractRemoteLinuxPackageInstaller::handleConnectionError);
|
||||
connect(d->installer, &SshRemoteProcessRunner::readyReadStandardOutput,
|
||||
this, &AbstractRemoteLinuxPackageInstaller::handleInstallerOutput);
|
||||
connect(d->installer, &SshRemoteProcessRunner::readyReadStandardError,
|
||||
this, &AbstractRemoteLinuxPackageInstaller::handleInstallerErrorOutput);
|
||||
connect(d->installer, &SshRemoteProcessRunner::finished,
|
||||
this, &AbstractRemoteLinuxPackageInstaller::handleInstallationFinished);
|
||||
d->m_device = deviceConfig;
|
||||
|
||||
QString cmdLine = installCommandLine(packageFilePath);
|
||||
if (removePackageFile)
|
||||
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
|
||||
d->installer->run(cmdLine, deviceConfig->sshParameters());
|
||||
d->isRunning = true;
|
||||
d->m_installer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"), {"-c", cmdLine}});
|
||||
d->m_installer.start();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
|
||||
{
|
||||
QTC_ASSERT(d->installer && d->isRunning, return);
|
||||
QTC_ASSERT(d->m_installer.state() != QProcess::NotRunning, return);
|
||||
|
||||
if (!d->killProcess)
|
||||
d->killProcess = new SshRemoteProcessRunner(this);
|
||||
d->killProcess->run(cancelInstallationCommandLine(), d->deviceConfig->sshParameters());
|
||||
setFinished();
|
||||
d->m_killer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"),
|
||||
{"-c", cancelInstallationCommandLine()}});
|
||||
d->m_killer.start();
|
||||
d->m_installer.close();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::handleConnectionError()
|
||||
{
|
||||
if (!d->isRunning)
|
||||
return;
|
||||
emit finished(tr("Connection failure: %1").arg(d->installer->lastConnectionErrorString()));
|
||||
setFinished();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::handleInstallationFinished()
|
||||
{
|
||||
const QString error = d->installer->errorString();
|
||||
if (!d->isRunning)
|
||||
return;
|
||||
|
||||
if (!error.isEmpty() || d->installer->exitCode() != 0)
|
||||
emit finished(tr("Installing package failed."));
|
||||
else if (!errorString().isEmpty())
|
||||
emit finished(errorString());
|
||||
else
|
||||
emit finished();
|
||||
|
||||
setFinished();
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::handleInstallerOutput()
|
||||
{
|
||||
emit stdoutData(QString::fromUtf8(d->installer->readAllStandardOutput()));
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::handleInstallerErrorOutput()
|
||||
{
|
||||
emit stderrData(QString::fromUtf8(d->installer->readAllStandardError()));
|
||||
}
|
||||
|
||||
void AbstractRemoteLinuxPackageInstaller::setFinished()
|
||||
{
|
||||
disconnect(d->installer, nullptr, this, nullptr);
|
||||
d->isRunning = false;
|
||||
}
|
||||
|
||||
|
||||
RemoteLinuxTarPackageInstaller::RemoteLinuxTarPackageInstaller(QObject *parent)
|
||||
: AbstractRemoteLinuxPackageInstaller(parent)
|
||||
{
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace RemoteLinux {
|
||||
|
||||
namespace Internal { class AbstractRemoteLinuxPackageInstallerPrivate; }
|
||||
@@ -55,20 +57,10 @@ protected:
|
||||
explicit AbstractRemoteLinuxPackageInstaller(QObject *parent = nullptr);
|
||||
|
||||
private:
|
||||
void handleConnectionError();
|
||||
void handleInstallationFinished();
|
||||
void handleInstallerOutput();
|
||||
void handleInstallerErrorOutput();
|
||||
|
||||
virtual QString installCommandLine(const QString &packageFilePath) const = 0;
|
||||
virtual QString cancelInstallationCommandLine() const = 0;
|
||||
|
||||
virtual void prepareInstallation() {}
|
||||
virtual QString errorString() const { return QString(); }
|
||||
|
||||
void setFinished();
|
||||
|
||||
Internal::AbstractRemoteLinuxPackageInstallerPrivate * const d;
|
||||
std::unique_ptr<Internal::AbstractRemoteLinuxPackageInstallerPrivate> d;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user