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 <projectexplorer/devicesupport/deviceusedportsgatherer.h>
#include <utils/port.h> #include <utils/port.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
#include <ssh/sftptransfer.h> #include <ssh/sftpsession.h>
#include <ssh/sshremoteprocess.h> #include <ssh/sshremoteprocess.h>
#include <ssh/sshconnection.h> #include <ssh/sshconnection.h>
#include <ssh/sshconnectionmanager.h> #include <ssh/sshconnectionmanager.h>
@@ -54,7 +54,7 @@ public:
SshConnection *connection = nullptr; SshConnection *connection = nullptr;
SshRemoteProcessPtr process; SshRemoteProcessPtr process;
DeviceUsedPortsGatherer portsGatherer; DeviceUsedPortsGatherer portsGatherer;
SftpTransferPtr sftpUpload; SftpSessionPtr sftpSession;
QProcess rsyncProcess; QProcess rsyncProcess;
State state = Inactive; State state = Inactive;
bool sftpWorks = false; bool sftpWorks = false;
@@ -108,7 +108,7 @@ void GenericLinuxDeviceTester::stopTest()
d->process->close(); d->process->close();
break; break;
case TestingSftp: case TestingSftp:
d->sftpUpload->stop(); d->sftpSession->quit();
break; break;
case TestingRsync: case TestingRsync:
d->rsyncProcess.disconnect(); d->rsyncProcess.disconnect();
@@ -190,25 +190,37 @@ void GenericLinuxDeviceTester::handlePortListReady()
} }
emit progressMessage(tr("Checking whether an SFTP connection can be set up...")); emit progressMessage(tr("Checking whether an SFTP connection can be set up..."));
d->sftpUpload = d->connection->createUpload(FilesToTransfer(), d->sftpSession = d->connection->createSftpSession();
FileTransferErrorHandling::Abort); connect(d->sftpSession.get(), &SftpSession::started,
connect(d->sftpUpload.get(), &SftpTransfer::done, this, &GenericLinuxDeviceTester::handleSftpStarted);
connect(d->sftpSession.get(), &SftpSession::done,
this, &GenericLinuxDeviceTester::handleSftpFinished); this, &GenericLinuxDeviceTester::handleSftpFinished);
d->state = TestingSftp; 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) void GenericLinuxDeviceTester::handleSftpFinished(const QString &error)
{ {
QTC_ASSERT(d->state == TestingSftp, return); QTC_ASSERT(d->state == TestingSftp, return);
if (!error.isEmpty()) { QString theError;
emit errorMessage(tr("Error setting up SFTP connection: %1\n").arg(error)); theError = error.isEmpty() ? tr("sftp finished unexpectedly.") : error;
d->sftpWorks = false; d->sftpWorks = false;
} else { emit errorMessage(tr("Error setting up SFTP connection: %1\n").arg(theError));
emit progressMessage(tr("SFTP service available.\n")); testRsync();
d->sftpWorks = true; }
}
void GenericLinuxDeviceTester::testRsync()
{
emit progressMessage(tr("Checking whether rsync works...")); emit progressMessage(tr("Checking whether rsync works..."));
connect(&d->rsyncProcess, &QProcess::errorOccurred, [this] { connect(&d->rsyncProcess, &QProcess::errorOccurred, [this] {
if (d->rsyncProcess.error() == QProcess::FailedToStart) if (d->rsyncProcess.error() == QProcess::FailedToStart)
@@ -255,9 +267,9 @@ void GenericLinuxDeviceTester::setFinished(TestResult result)
{ {
d->state = Inactive; d->state = Inactive;
disconnect(&d->portsGatherer, nullptr, this, nullptr); disconnect(&d->portsGatherer, nullptr, this, nullptr);
if (d->sftpUpload) { if (d->sftpSession) {
disconnect(d->sftpUpload.get(), nullptr, this, nullptr); disconnect(d->sftpSession.get(), nullptr, this, nullptr);
d->sftpUpload.release()->deleteLater(); d->sftpSession.release()->deleteLater();
} }
if (d->connection) { if (d->connection) {
disconnect(d->connection, nullptr, this, nullptr); disconnect(d->connection, nullptr, this, nullptr);

View File

@@ -50,7 +50,9 @@ private:
void handleProcessFinished(const QString &error); void handleProcessFinished(const QString &error);
void handlePortsGatheringError(const QString &message); void handlePortsGatheringError(const QString &message);
void handlePortListReady(); void handlePortListReady();
void handleSftpStarted();
void handleSftpFinished(const QString &error); void handleSftpFinished(const QString &error);
void testRsync();
void handleRsyncFinished(); void handleRsyncFinished();
void setFinished(ProjectExplorer::DeviceTester::TestResult result); void setFinished(ProjectExplorer::DeviceTester::TestResult result);