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 "remotelinuxpackageinstaller.h"
|
||||||
|
|
||||||
#include <projectexplorer/devicesupport/idevice.h>
|
#include <projectexplorer/devicesupport/idevice.h>
|
||||||
#include <ssh/sshremoteprocessrunner.h>
|
|
||||||
#include <utils/qtcassert.h>
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
#include <utils/qtcprocess.h>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace QSsh;
|
using namespace QSsh;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -39,10 +41,9 @@ namespace Internal {
|
|||||||
class AbstractRemoteLinuxPackageInstallerPrivate
|
class AbstractRemoteLinuxPackageInstallerPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool isRunning = false;
|
IDevice::ConstPtr m_device;
|
||||||
IDevice::ConstPtr deviceConfig;
|
QtcProcess m_installer;
|
||||||
SshRemoteProcessRunner *installer = nullptr;
|
QtcProcess m_killer;
|
||||||
SshRemoteProcessRunner *killProcess = nullptr;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -50,89 +51,45 @@ public:
|
|||||||
AbstractRemoteLinuxPackageInstaller::AbstractRemoteLinuxPackageInstaller(QObject *parent)
|
AbstractRemoteLinuxPackageInstaller::AbstractRemoteLinuxPackageInstaller(QObject *parent)
|
||||||
: QObject(parent), d(new Internal::AbstractRemoteLinuxPackageInstallerPrivate)
|
: 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()
|
AbstractRemoteLinuxPackageInstaller::~AbstractRemoteLinuxPackageInstaller() = default;
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig,
|
void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr &deviceConfig,
|
||||||
const QString &packageFilePath, bool removePackageFile)
|
const QString &packageFilePath, bool removePackageFile)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!d->isRunning, return);
|
QTC_ASSERT(d->m_installer.state() == QProcess::NotRunning, return);
|
||||||
|
|
||||||
d->deviceConfig = deviceConfig;
|
d->m_device = 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);
|
|
||||||
|
|
||||||
QString cmdLine = installCommandLine(packageFilePath);
|
QString cmdLine = installCommandLine(packageFilePath);
|
||||||
if (removePackageFile)
|
if (removePackageFile)
|
||||||
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
|
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
|
||||||
d->installer->run(cmdLine, deviceConfig->sshParameters());
|
d->m_installer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"), {"-c", cmdLine}});
|
||||||
d->isRunning = true;
|
d->m_installer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
|
void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
|
||||||
{
|
{
|
||||||
QTC_ASSERT(d->installer && d->isRunning, return);
|
QTC_ASSERT(d->m_installer.state() != QProcess::NotRunning, return);
|
||||||
|
|
||||||
if (!d->killProcess)
|
d->m_killer.setCommand({d->m_device->mapToGlobalPath("/bin/sh"),
|
||||||
d->killProcess = new SshRemoteProcessRunner(this);
|
{"-c", cancelInstallationCommandLine()}});
|
||||||
d->killProcess->run(cancelInstallationCommandLine(), d->deviceConfig->sshParameters());
|
d->m_killer.start();
|
||||||
setFinished();
|
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)
|
RemoteLinuxTarPackageInstaller::RemoteLinuxTarPackageInstaller(QObject *parent)
|
||||||
: AbstractRemoteLinuxPackageInstaller(parent)
|
: AbstractRemoteLinuxPackageInstaller(parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -31,6 +31,8 @@
|
|||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
|
|
||||||
namespace Internal { class AbstractRemoteLinuxPackageInstallerPrivate; }
|
namespace Internal { class AbstractRemoteLinuxPackageInstallerPrivate; }
|
||||||
@@ -55,20 +57,10 @@ protected:
|
|||||||
explicit AbstractRemoteLinuxPackageInstaller(QObject *parent = nullptr);
|
explicit AbstractRemoteLinuxPackageInstaller(QObject *parent = nullptr);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleConnectionError();
|
|
||||||
void handleInstallationFinished();
|
|
||||||
void handleInstallerOutput();
|
|
||||||
void handleInstallerErrorOutput();
|
|
||||||
|
|
||||||
virtual QString installCommandLine(const QString &packageFilePath) const = 0;
|
virtual QString installCommandLine(const QString &packageFilePath) const = 0;
|
||||||
virtual QString cancelInstallationCommandLine() const = 0;
|
virtual QString cancelInstallationCommandLine() const = 0;
|
||||||
|
|
||||||
virtual void prepareInstallation() {}
|
std::unique_ptr<Internal::AbstractRemoteLinuxPackageInstallerPrivate> d;
|
||||||
virtual QString errorString() const { return QString(); }
|
|
||||||
|
|
||||||
void setFinished();
|
|
||||||
|
|
||||||
Internal::AbstractRemoteLinuxPackageInstallerPrivate * const d;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user