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 <hjk@qt.io>
This commit is contained in:
Christian Kandeler
2018-12-19 16:18:04 +01:00
parent 66944dc4e9
commit 8098588a97
2 changed files with 31 additions and 17 deletions

View File

@@ -31,7 +31,7 @@
#include <projectexplorer/devicesupport/deviceusedportsgatherer.h>
#include <utils/port.h>
#include <utils/qtcassert.h>
#include <ssh/sftptransfer.h>
#include <ssh/sftpsession.h>
#include <ssh/sshremoteprocess.h>
#include <ssh/sshconnection.h>
#include <ssh/sshconnectionmanager.h>
@@ -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));
QString theError;
theError = error.isEmpty() ? tr("sftp finished unexpectedly.") : error;
d->sftpWorks = false;
} else {
emit progressMessage(tr("SFTP service available.\n"));
d->sftpWorks = true;
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);

View File

@@ -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);