From 8098588a97b79e64a4fcdcb66db2cabdf62f10b5 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Wed, 19 Dec 2018 16:18:04 +0100 Subject: [PATCH] RemoteLinux: Do not use SftpTransfer in device tester When the -b switch is used, sftp does not invoke the askpass tool, so this mode is not suitable for an initial device test. Use SftpSession instead. Change-Id: I0ad6e79e821851b6fae2cd11c6194c1956a73d02 Reviewed-by: hjk --- src/plugins/remotelinux/linuxdevicetester.cpp | 46 ++++++++++++------- src/plugins/remotelinux/linuxdevicetester.h | 2 + 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/src/plugins/remotelinux/linuxdevicetester.cpp b/src/plugins/remotelinux/linuxdevicetester.cpp index b6a470ab076..92692c97cf7 100644 --- a/src/plugins/remotelinux/linuxdevicetester.cpp +++ b/src/plugins/remotelinux/linuxdevicetester.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include @@ -54,7 +54,7 @@ public: SshConnection *connection = nullptr; SshRemoteProcessPtr process; DeviceUsedPortsGatherer portsGatherer; - SftpTransferPtr sftpUpload; + SftpSessionPtr sftpSession; QProcess rsyncProcess; State state = Inactive; bool sftpWorks = false; @@ -108,7 +108,7 @@ void GenericLinuxDeviceTester::stopTest() d->process->close(); break; case TestingSftp: - d->sftpUpload->stop(); + d->sftpSession->quit(); break; case TestingRsync: d->rsyncProcess.disconnect(); @@ -190,25 +190,37 @@ void GenericLinuxDeviceTester::handlePortListReady() } emit progressMessage(tr("Checking whether an SFTP connection can be set up...")); - d->sftpUpload = d->connection->createUpload(FilesToTransfer(), - FileTransferErrorHandling::Abort); - connect(d->sftpUpload.get(), &SftpTransfer::done, + d->sftpSession = d->connection->createSftpSession(); + connect(d->sftpSession.get(), &SftpSession::started, + this, &GenericLinuxDeviceTester::handleSftpStarted); + connect(d->sftpSession.get(), &SftpSession::done, this, &GenericLinuxDeviceTester::handleSftpFinished); d->state = TestingSftp; - d->sftpUpload->start(); + d->sftpSession->start(); +} + +void GenericLinuxDeviceTester::handleSftpStarted() +{ + QTC_ASSERT(d->state == TestingSftp, return); + emit progressMessage(tr("SFTP service available.\n")); + d->sftpWorks = true; + disconnect(d->sftpSession.get(), nullptr, this, nullptr); + d->sftpSession->quit(); + testRsync(); } void GenericLinuxDeviceTester::handleSftpFinished(const QString &error) { QTC_ASSERT(d->state == TestingSftp, return); - if (!error.isEmpty()) { - emit errorMessage(tr("Error setting up SFTP connection: %1\n").arg(error)); - d->sftpWorks = false; - } else { - emit progressMessage(tr("SFTP service available.\n")); - d->sftpWorks = true; - } + QString theError; + theError = error.isEmpty() ? tr("sftp finished unexpectedly.") : error; + d->sftpWorks = false; + emit errorMessage(tr("Error setting up SFTP connection: %1\n").arg(theError)); + testRsync(); +} +void GenericLinuxDeviceTester::testRsync() +{ emit progressMessage(tr("Checking whether rsync works...")); connect(&d->rsyncProcess, &QProcess::errorOccurred, [this] { if (d->rsyncProcess.error() == QProcess::FailedToStart) @@ -255,9 +267,9 @@ void GenericLinuxDeviceTester::setFinished(TestResult result) { d->state = Inactive; disconnect(&d->portsGatherer, nullptr, this, nullptr); - if (d->sftpUpload) { - disconnect(d->sftpUpload.get(), nullptr, this, nullptr); - d->sftpUpload.release()->deleteLater(); + if (d->sftpSession) { + disconnect(d->sftpSession.get(), nullptr, this, nullptr); + d->sftpSession.release()->deleteLater(); } if (d->connection) { disconnect(d->connection, nullptr, this, nullptr); diff --git a/src/plugins/remotelinux/linuxdevicetester.h b/src/plugins/remotelinux/linuxdevicetester.h index 9aefdda33f7..4cc6c7f9af1 100644 --- a/src/plugins/remotelinux/linuxdevicetester.h +++ b/src/plugins/remotelinux/linuxdevicetester.h @@ -50,7 +50,9 @@ private: void handleProcessFinished(const QString &error); void handlePortsGatheringError(const QString &message); void handlePortListReady(); + void handleSftpStarted(); void handleSftpFinished(const QString &error); + void testRsync(); void handleRsyncFinished(); void setFinished(ProjectExplorer::DeviceTester::TestResult result);