From 4634b058fa79b708aa8883ae1dfbed931317c819 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Tue, 10 May 2022 18:31:42 +0200 Subject: [PATCH] AbstractUploadAndInstallPackageService: Use FileTransfer Use LinuxDevice::transferFiles() instead of SftpTransfer. Get rid of unused now PackageUploader. Change-Id: Ibea4557c3e003cd9d7d3692db5bec6b82dcad71a Reviewed-by: Christian Kandeler --- src/plugins/remotelinux/CMakeLists.txt | 1 - .../abstractremotelinuxdeployservice.cpp | 4 +- ...abstractuploadandinstallpackageservice.cpp | 43 ++++--- .../abstractuploadandinstallpackageservice.h | 7 +- src/plugins/remotelinux/packageuploader.cpp | 108 ------------------ src/plugins/remotelinux/packageuploader.h | 70 ------------ src/plugins/remotelinux/remotelinux.qbs | 2 - 7 files changed, 28 insertions(+), 207 deletions(-) delete mode 100644 src/plugins/remotelinux/packageuploader.cpp delete mode 100644 src/plugins/remotelinux/packageuploader.h diff --git a/src/plugins/remotelinux/CMakeLists.txt b/src/plugins/remotelinux/CMakeLists.txt index 2c3807af868..dc08806c748 100644 --- a/src/plugins/remotelinux/CMakeLists.txt +++ b/src/plugins/remotelinux/CMakeLists.txt @@ -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 diff --git a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp index 8d44a4893a2..9a30d113586 100644 --- a/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp +++ b/src/plugins/remotelinux/abstractremotelinuxdeployservice.cpp @@ -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(); } diff --git a/src/plugins/remotelinux/abstractuploadandinstallpackageservice.cpp b/src/plugins/remotelinux/abstractuploadandinstallpackageservice.cpp index f307ed2dcc9..04ee35768db 100644 --- a/src/plugins/remotelinux/abstractuploadandinstallpackageservice.cpp +++ b/src/plugins/remotelinux/abstractuploadandinstallpackageservice.cpp @@ -25,14 +25,14 @@ #include "abstractuploadandinstallpackageservice.h" -#include "packageuploader.h" +#include "linuxdevice.h" #include "remotelinuxpackageinstaller.h" #include +#include #include #include -#include 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 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(); + 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(); } diff --git a/src/plugins/remotelinux/abstractuploadandinstallpackageservice.h b/src/plugins/remotelinux/abstractuploadandinstallpackageservice.h index a15a640a228..82d9e6cd175 100644 --- a/src/plugins/remotelinux/abstractuploadandinstallpackageservice.h +++ b/src/plugins/remotelinux/abstractuploadandinstallpackageservice.h @@ -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; diff --git a/src/plugins/remotelinux/packageuploader.cpp b/src/plugins/remotelinux/packageuploader.cpp deleted file mode 100644 index d73282bd193..00000000000 --- a/src/plugins/remotelinux/packageuploader.cpp +++ /dev/null @@ -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 -#include -#include - -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 diff --git a/src/plugins/remotelinux/packageuploader.h b/src/plugins/remotelinux/packageuploader.h deleted file mode 100644 index 99499e9a16d..00000000000 --- a/src/plugins/remotelinux/packageuploader.h +++ /dev/null @@ -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 -#include - -#include - -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 diff --git a/src/plugins/remotelinux/remotelinux.qbs b/src/plugins/remotelinux/remotelinux.qbs index 3440fa9689e..f703d023ee8 100644 --- a/src/plugins/remotelinux/remotelinux.qbs +++ b/src/plugins/remotelinux/remotelinux.qbs @@ -43,8 +43,6 @@ Project { "linuxprocessinterface.h", "makeinstallstep.cpp", "makeinstallstep.h", - "packageuploader.cpp", - "packageuploader.h", "publickeydeploymentdialog.cpp", "publickeydeploymentdialog.h", "remotelinux.qrc",