AbstractUploadAndInstallPackageService: Use FileTransfer

Use LinuxDevice::transferFiles() instead of SftpTransfer.
Get rid of unused now PackageUploader.

Change-Id: Ibea4557c3e003cd9d7d3692db5bec6b82dcad71a
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-10 18:31:42 +02:00
parent 8eb12ea614
commit 4634b058fa
7 changed files with 28 additions and 207 deletions

View File

@@ -17,7 +17,6 @@ add_qtc_plugin(RemoteLinux
linuxdevicetester.cpp linuxdevicetester.h
linuxprocessinterface.h
makeinstallstep.cpp makeinstallstep.h
packageuploader.cpp packageuploader.h
publickeydeploymentdialog.cpp publickeydeploymentdialog.h
remotelinux.qrc
remotelinux_constants.h

View File

@@ -204,8 +204,8 @@ void AbstractRemoteLinuxDeployService::handleDeviceSetupDone(bool success)
connect(d->connection, &SshConnection::connected,
this, &AbstractRemoteLinuxDeployService::handleConnected);
emit progressMessage(tr("Connecting to device \"%1\" (%2).")
.arg(deviceConfiguration()->displayName())
.arg(deviceConfiguration()->sshParameters().host()));
.arg(deviceConfiguration()->displayName(),
deviceConfiguration()->sshParameters().host()));
if (d->connection->state() == SshConnection::Unconnected)
d->connection->connectToHost();
}

View File

@@ -25,14 +25,14 @@
#include "abstractuploadandinstallpackageservice.h"
#include "packageuploader.h"
#include "linuxdevice.h"
#include "remotelinuxpackageinstaller.h"
#include <projectexplorer/deployablefile.h>
#include <utils/processinterface.h>
#include <utils/qtcassert.h>
#include <QDateTime>
#include <QString>
using namespace ProjectExplorer;
using namespace Utils;
@@ -46,14 +46,8 @@ enum State { Inactive, Uploading, Installing };
class AbstractUploadAndInstallPackageServicePrivate
{
public:
AbstractUploadAndInstallPackageServicePrivate()
: state(Inactive), uploader(new PackageUploader)
{
}
~AbstractUploadAndInstallPackageServicePrivate() { delete uploader; }
State state;
PackageUploader * const uploader;
State state = Inactive;
std::unique_ptr<FileTransfer> uploader;
Utils::FilePath packageFilePath;
};
@@ -103,13 +97,18 @@ void AbstractUploadAndInstallPackageService::doDeploy()
QTC_ASSERT(d->state == Inactive, return);
d->state = Uploading;
const QString fileName = d->packageFilePath.fileName();
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + fileName;
connect(d->uploader, &PackageUploader::progress,
this, &AbstractUploadAndInstallPackageService::progressMessage);
connect(d->uploader, &PackageUploader::uploadFinished,
this, &AbstractUploadAndInstallPackageService::handleUploadFinished);
d->uploader->uploadPackage(connection(), d->packageFilePath.toString(), remoteFilePath);
LinuxDevice::ConstPtr linuxDevice = deviceConfiguration().dynamicCast<const LinuxDevice>();
QTC_ASSERT(linuxDevice, return);
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + d->packageFilePath.fileName();
const FilesToTransfer files {{d->packageFilePath,
deviceConfiguration()->filePath(remoteFilePath)}};
d->uploader.reset(linuxDevice->createFileTransfer(files));
connect(d->uploader.get(), &FileTransfer::done, this,
&AbstractUploadAndInstallPackageService::handleUploadFinished);
connect(d->uploader.get(), &FileTransfer::progress, this,
&AbstractUploadAndInstallPackageService::progressMessage);
d->uploader->start();
}
void AbstractUploadAndInstallPackageService::stopDeployment()
@@ -119,7 +118,7 @@ void AbstractUploadAndInstallPackageService::stopDeployment()
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
break;
case Uploading:
d->uploader->cancelUpload();
d->uploader->stop();
setFinished();
break;
case Installing:
@@ -129,12 +128,12 @@ void AbstractUploadAndInstallPackageService::stopDeployment()
}
}
void AbstractUploadAndInstallPackageService::handleUploadFinished(const QString &errorMsg)
void AbstractUploadAndInstallPackageService::handleUploadFinished(const ProcessResultData &resultData)
{
QTC_ASSERT(d->state == Uploading, return);
if (!errorMsg.isEmpty()) {
emit errorMessage(errorMsg);
if (resultData.m_error != QProcess::UnknownError) {
emit errorMessage(resultData.m_errorString);
setFinished();
return;
}
@@ -168,7 +167,7 @@ void AbstractUploadAndInstallPackageService::handleInstallationFinished(const QS
void AbstractUploadAndInstallPackageService::setFinished()
{
d->state = Inactive;
disconnect(d->uploader, nullptr, this, nullptr);
d->uploader->stop();
disconnect(packageInstaller(), nullptr, this, nullptr);
handleDeploymentDone();
}

View File

@@ -28,7 +28,10 @@
#include "abstractremotelinuxdeployservice.h"
#include "remotelinux_export.h"
namespace Utils { class FilePath; }
namespace Utils {
class FilePath;
class ProcessResultData;
}
namespace RemoteLinux {
class AbstractRemoteLinuxPackageInstaller;
@@ -47,7 +50,7 @@ protected:
~AbstractUploadAndInstallPackageService() override;
private:
void handleUploadFinished(const QString &errorMsg);
void handleUploadFinished(const Utils::ProcessResultData &resultData);
void handleInstallationFinished(const QString &errorMsg);
virtual AbstractRemoteLinuxPackageInstaller *packageInstaller() const = 0;

View File

@@ -1,108 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "packageuploader.h"
#include <utils/qtcassert.h>
#include <ssh/sftptransfer.h>
#include <ssh/sshconnection.h>
using namespace QSsh;
namespace RemoteLinux {
namespace Internal {
PackageUploader::PackageUploader(QObject *parent) :
QObject(parent), m_state(Inactive), m_connection(nullptr)
{
}
PackageUploader::~PackageUploader() = default;
void PackageUploader::uploadPackage(SshConnection *connection,
const QString &localFilePath, const QString &remoteFilePath)
{
QTC_ASSERT(m_state == Inactive, return);
setState(Uploading);
emit progress(tr("Preparing SFTP connection..."));
m_connection = connection;
connect(m_connection, &SshConnection::errorOccurred,
this, &PackageUploader::handleConnectionFailure);
m_uploader = m_connection->createUpload({FileToTransfer(localFilePath, remoteFilePath)});
connect(m_uploader.get(), &SftpTransfer::done, this, &PackageUploader::handleUploadDone);
m_uploader->start();
}
void PackageUploader::cancelUpload()
{
QTC_ASSERT(m_state == Uploading, return);
setState(Inactive);
emit uploadFinished(tr("Package upload canceled."));
}
void PackageUploader::handleConnectionFailure()
{
if (m_state == Inactive)
return;
const QString errorMsg = m_connection->errorString();
setState(Inactive);
emit uploadFinished(tr("Connection failed: %1").arg(errorMsg));
}
void PackageUploader::handleUploadDone(const QString &errorMsg)
{
QTC_ASSERT(m_state == Uploading, return);
setState(Inactive);
if (!errorMsg.isEmpty())
emit uploadFinished(tr("Failed to upload package: %2").arg(errorMsg));
else
emit uploadFinished();
}
void PackageUploader::setState(State newState)
{
if (m_state == newState)
return;
if (newState == Inactive) {
if (m_uploader) {
disconnect(m_uploader.get(), nullptr, this, nullptr);
m_uploader->stop();
m_uploader.release()->deleteLater();
}
if (m_connection) {
disconnect(m_connection, nullptr, this, nullptr);
m_connection = nullptr;
}
}
m_state = newState;
}
} // namespace Internal
} // namespace RemoteLinux

View File

@@ -1,70 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#pragma once
#include <QObject>
#include <QString>
#include <ssh/sftpdefs.h>
namespace QSsh {
class SftpChannel;
class SshConnection;
}
namespace RemoteLinux {
namespace Internal {
class PackageUploader : public QObject
{
Q_OBJECT
public:
explicit PackageUploader(QObject *parent = nullptr);
~PackageUploader() override;
// Connection has to be established already.
void uploadPackage(QSsh::SshConnection *connection,
const QString &localFilePath, const QString &remoteFilePath);
void cancelUpload();
signals:
void progress(const QString &message);
void uploadFinished(const QString &errorMsg = QString());
private:
enum State { Uploading, Inactive };
void handleConnectionFailure();
void handleUploadDone(const QString &error);
void setState(State newState);
State m_state;
QSsh::SshConnection *m_connection;
QSsh::SftpTransferPtr m_uploader;
};
} // namespace Internal
} // namespace RemoteLinux

View File

@@ -43,8 +43,6 @@ Project {
"linuxprocessinterface.h",
"makeinstallstep.cpp",
"makeinstallstep.h",
"packageuploader.cpp",
"packageuploader.h",
"publickeydeploymentdialog.cpp",
"publickeydeploymentdialog.h",
"remotelinux.qrc",