forked from qt-creator/qt-creator
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:
@@ -17,7 +17,6 @@ add_qtc_plugin(RemoteLinux
|
|||||||
linuxdevicetester.cpp linuxdevicetester.h
|
linuxdevicetester.cpp linuxdevicetester.h
|
||||||
linuxprocessinterface.h
|
linuxprocessinterface.h
|
||||||
makeinstallstep.cpp makeinstallstep.h
|
makeinstallstep.cpp makeinstallstep.h
|
||||||
packageuploader.cpp packageuploader.h
|
|
||||||
publickeydeploymentdialog.cpp publickeydeploymentdialog.h
|
publickeydeploymentdialog.cpp publickeydeploymentdialog.h
|
||||||
remotelinux.qrc
|
remotelinux.qrc
|
||||||
remotelinux_constants.h
|
remotelinux_constants.h
|
||||||
|
@@ -204,8 +204,8 @@ void AbstractRemoteLinuxDeployService::handleDeviceSetupDone(bool success)
|
|||||||
connect(d->connection, &SshConnection::connected,
|
connect(d->connection, &SshConnection::connected,
|
||||||
this, &AbstractRemoteLinuxDeployService::handleConnected);
|
this, &AbstractRemoteLinuxDeployService::handleConnected);
|
||||||
emit progressMessage(tr("Connecting to device \"%1\" (%2).")
|
emit progressMessage(tr("Connecting to device \"%1\" (%2).")
|
||||||
.arg(deviceConfiguration()->displayName())
|
.arg(deviceConfiguration()->displayName(),
|
||||||
.arg(deviceConfiguration()->sshParameters().host()));
|
deviceConfiguration()->sshParameters().host()));
|
||||||
if (d->connection->state() == SshConnection::Unconnected)
|
if (d->connection->state() == SshConnection::Unconnected)
|
||||||
d->connection->connectToHost();
|
d->connection->connectToHost();
|
||||||
}
|
}
|
||||||
|
@@ -25,14 +25,14 @@
|
|||||||
|
|
||||||
#include "abstractuploadandinstallpackageservice.h"
|
#include "abstractuploadandinstallpackageservice.h"
|
||||||
|
|
||||||
#include "packageuploader.h"
|
#include "linuxdevice.h"
|
||||||
#include "remotelinuxpackageinstaller.h"
|
#include "remotelinuxpackageinstaller.h"
|
||||||
|
|
||||||
#include <projectexplorer/deployablefile.h>
|
#include <projectexplorer/deployablefile.h>
|
||||||
|
#include <utils/processinterface.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QString>
|
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -46,14 +46,8 @@ enum State { Inactive, Uploading, Installing };
|
|||||||
class AbstractUploadAndInstallPackageServicePrivate
|
class AbstractUploadAndInstallPackageServicePrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AbstractUploadAndInstallPackageServicePrivate()
|
State state = Inactive;
|
||||||
: state(Inactive), uploader(new PackageUploader)
|
std::unique_ptr<FileTransfer> uploader;
|
||||||
{
|
|
||||||
}
|
|
||||||
~AbstractUploadAndInstallPackageServicePrivate() { delete uploader; }
|
|
||||||
|
|
||||||
State state;
|
|
||||||
PackageUploader * const uploader;
|
|
||||||
Utils::FilePath packageFilePath;
|
Utils::FilePath packageFilePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,13 +97,18 @@ void AbstractUploadAndInstallPackageService::doDeploy()
|
|||||||
QTC_ASSERT(d->state == Inactive, return);
|
QTC_ASSERT(d->state == Inactive, return);
|
||||||
|
|
||||||
d->state = Uploading;
|
d->state = Uploading;
|
||||||
const QString fileName = d->packageFilePath.fileName();
|
|
||||||
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + fileName;
|
LinuxDevice::ConstPtr linuxDevice = deviceConfiguration().dynamicCast<const LinuxDevice>();
|
||||||
connect(d->uploader, &PackageUploader::progress,
|
QTC_ASSERT(linuxDevice, return);
|
||||||
this, &AbstractUploadAndInstallPackageService::progressMessage);
|
const QString remoteFilePath = uploadDir() + QLatin1Char('/') + d->packageFilePath.fileName();
|
||||||
connect(d->uploader, &PackageUploader::uploadFinished,
|
const FilesToTransfer files {{d->packageFilePath,
|
||||||
this, &AbstractUploadAndInstallPackageService::handleUploadFinished);
|
deviceConfiguration()->filePath(remoteFilePath)}};
|
||||||
d->uploader->uploadPackage(connection(), d->packageFilePath.toString(), 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()
|
void AbstractUploadAndInstallPackageService::stopDeployment()
|
||||||
@@ -119,7 +118,7 @@ void AbstractUploadAndInstallPackageService::stopDeployment()
|
|||||||
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
|
qWarning("%s: Unexpected state 'Inactive'.", Q_FUNC_INFO);
|
||||||
break;
|
break;
|
||||||
case Uploading:
|
case Uploading:
|
||||||
d->uploader->cancelUpload();
|
d->uploader->stop();
|
||||||
setFinished();
|
setFinished();
|
||||||
break;
|
break;
|
||||||
case Installing:
|
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);
|
QTC_ASSERT(d->state == Uploading, return);
|
||||||
|
|
||||||
if (!errorMsg.isEmpty()) {
|
if (resultData.m_error != QProcess::UnknownError) {
|
||||||
emit errorMessage(errorMsg);
|
emit errorMessage(resultData.m_errorString);
|
||||||
setFinished();
|
setFinished();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -168,7 +167,7 @@ void AbstractUploadAndInstallPackageService::handleInstallationFinished(const QS
|
|||||||
void AbstractUploadAndInstallPackageService::setFinished()
|
void AbstractUploadAndInstallPackageService::setFinished()
|
||||||
{
|
{
|
||||||
d->state = Inactive;
|
d->state = Inactive;
|
||||||
disconnect(d->uploader, nullptr, this, nullptr);
|
d->uploader->stop();
|
||||||
disconnect(packageInstaller(), nullptr, this, nullptr);
|
disconnect(packageInstaller(), nullptr, this, nullptr);
|
||||||
handleDeploymentDone();
|
handleDeploymentDone();
|
||||||
}
|
}
|
||||||
|
@@ -28,7 +28,10 @@
|
|||||||
#include "abstractremotelinuxdeployservice.h"
|
#include "abstractremotelinuxdeployservice.h"
|
||||||
#include "remotelinux_export.h"
|
#include "remotelinux_export.h"
|
||||||
|
|
||||||
namespace Utils { class FilePath; }
|
namespace Utils {
|
||||||
|
class FilePath;
|
||||||
|
class ProcessResultData;
|
||||||
|
}
|
||||||
|
|
||||||
namespace RemoteLinux {
|
namespace RemoteLinux {
|
||||||
class AbstractRemoteLinuxPackageInstaller;
|
class AbstractRemoteLinuxPackageInstaller;
|
||||||
@@ -47,7 +50,7 @@ protected:
|
|||||||
~AbstractUploadAndInstallPackageService() override;
|
~AbstractUploadAndInstallPackageService() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void handleUploadFinished(const QString &errorMsg);
|
void handleUploadFinished(const Utils::ProcessResultData &resultData);
|
||||||
void handleInstallationFinished(const QString &errorMsg);
|
void handleInstallationFinished(const QString &errorMsg);
|
||||||
|
|
||||||
virtual AbstractRemoteLinuxPackageInstaller *packageInstaller() const = 0;
|
virtual AbstractRemoteLinuxPackageInstaller *packageInstaller() const = 0;
|
||||||
|
@@ -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
|
|
@@ -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
|
|
@@ -43,8 +43,6 @@ Project {
|
|||||||
"linuxprocessinterface.h",
|
"linuxprocessinterface.h",
|
||||||
"makeinstallstep.cpp",
|
"makeinstallstep.cpp",
|
||||||
"makeinstallstep.h",
|
"makeinstallstep.h",
|
||||||
"packageuploader.cpp",
|
|
||||||
"packageuploader.h",
|
|
||||||
"publickeydeploymentdialog.cpp",
|
"publickeydeploymentdialog.cpp",
|
||||||
"publickeydeploymentdialog.h",
|
"publickeydeploymentdialog.h",
|
||||||
"remotelinux.qrc",
|
"remotelinux.qrc",
|
||||||
|
Reference in New Issue
Block a user