forked from qt-creator/qt-creator
QtcProcess: Introduce done() signal
Introduce QtcProcess::done() signal. It's similar to QtcProcess::finished() signal, but also emitted when process failed to start (so after QProcess::FailedToStart error occurred). SshRemoteProcess::finished() signal was already behaving like this. So, we remove special handling of FailedToStart error in this class and connect all clients of SshRemoteProcess to done() signal, instead of finished(). Task-number: QTCREATORBUG-27232 Change-Id: If4240e2172f3f706e812bca669a1d5b24bdc3285 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -62,14 +62,7 @@ void SshRemoteProcess::emitFinished()
|
||||
{
|
||||
if (exitStatus() == QProcess::CrashExit)
|
||||
m_errorString = tr("The ssh process crashed: %1").arg(errorString());
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void SshRemoteProcess::emitErrorOccurred(QProcess::ProcessError error)
|
||||
{
|
||||
if (error == QProcess::FailedToStart)
|
||||
emit finished();
|
||||
emit errorOccurred(error);
|
||||
QtcProcess::emitFinished();
|
||||
}
|
||||
|
||||
void SshRemoteProcess::start()
|
||||
|
@@ -50,7 +50,6 @@ public:
|
||||
|
||||
protected:
|
||||
void emitFinished() override;
|
||||
void emitErrorOccurred(QProcess::ProcessError error) override;
|
||||
|
||||
private:
|
||||
QString m_remoteCommand;
|
||||
|
@@ -36,6 +36,8 @@
|
||||
running a remote process over an SSH connection.
|
||||
*/
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
namespace QSsh {
|
||||
namespace Internal {
|
||||
namespace {
|
||||
@@ -109,13 +111,13 @@ void SshRemoteProcessRunner::handleConnected()
|
||||
setState(Connected);
|
||||
|
||||
d->m_process = d->m_connection->createRemoteProcess(d->m_command);
|
||||
connect(d->m_process.get(), &SshRemoteProcess::started,
|
||||
connect(d->m_process.get(), &QtcProcess::started,
|
||||
this, &SshRemoteProcessRunner::handleProcessStarted);
|
||||
connect(d->m_process.get(), &SshRemoteProcess::finished,
|
||||
connect(d->m_process.get(), &QtcProcess::done,
|
||||
this, &SshRemoteProcessRunner::handleProcessFinished);
|
||||
connect(d->m_process.get(), &SshRemoteProcess::readyReadStandardOutput,
|
||||
connect(d->m_process.get(), &QtcProcess::readyReadStandardOutput,
|
||||
this, &SshRemoteProcessRunner::readyReadStandardOutput);
|
||||
connect(d->m_process.get(), &SshRemoteProcess::readyReadStandardError,
|
||||
connect(d->m_process.get(), &QtcProcess::readyReadStandardError,
|
||||
this, &SshRemoteProcessRunner::readyReadStandardError);
|
||||
d->m_process->start();
|
||||
}
|
||||
|
@@ -590,6 +590,8 @@ public:
|
||||
void handleError(QProcess::ProcessError error);
|
||||
void clearForRun();
|
||||
|
||||
void emitErrorOccurred(QProcess::ProcessError error);
|
||||
|
||||
ProcessResult interpretExitCode(int exitCode);
|
||||
|
||||
QTextCodec *m_codec = QTextCodec::codecForLocale();
|
||||
@@ -701,11 +703,7 @@ void QtcProcess::emitStarted()
|
||||
void QtcProcess::emitFinished()
|
||||
{
|
||||
emit finished();
|
||||
}
|
||||
|
||||
void QtcProcess::emitErrorOccurred(QProcess::ProcessError error)
|
||||
{
|
||||
emit errorOccurred(error);
|
||||
emit done();
|
||||
}
|
||||
|
||||
void QtcProcess::setProcessInterface(ProcessInterface *interface)
|
||||
@@ -1647,7 +1645,14 @@ void QtcProcessPrivate::handleError(QProcess::ProcessError error)
|
||||
if (m_eventLoop)
|
||||
m_eventLoop->quit();
|
||||
|
||||
q->emitErrorOccurred(error);
|
||||
emitErrorOccurred(error);
|
||||
}
|
||||
|
||||
void QtcProcessPrivate::emitErrorOccurred(QProcess::ProcessError error)
|
||||
{
|
||||
emit q->errorOccurred(error);
|
||||
if (error == QProcess::FailedToStart)
|
||||
emit q->done();
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -189,6 +189,8 @@ public:
|
||||
signals:
|
||||
void started();
|
||||
void finished();
|
||||
void done(); // The same as finished() with the addition it's being also emitted after
|
||||
// FailedToStart error occurred.
|
||||
void errorOccurred(QProcess::ProcessError error);
|
||||
void readyReadStandardOutput();
|
||||
void readyReadStandardError();
|
||||
@@ -197,7 +199,6 @@ protected:
|
||||
// TODO: remove these methods on QtcProcess de-virtualization
|
||||
virtual void emitStarted();
|
||||
virtual void emitFinished();
|
||||
virtual void emitErrorOccurred(QProcess::ProcessError error);
|
||||
|
||||
private:
|
||||
void setProcessInterface(ProcessInterface *interface);
|
||||
|
@@ -197,14 +197,14 @@ void SshDeviceProcess::handleConnected()
|
||||
setCommand(d->remoteProcess->fullLocalCommandLine(true));
|
||||
QtcProcess::start();
|
||||
} else {
|
||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::started,
|
||||
connect(d->remoteProcess.get(), &QtcProcess::started,
|
||||
this, &SshDeviceProcess::handleProcessStarted);
|
||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::finished, this, [this] {
|
||||
connect(d->remoteProcess.get(), &QtcProcess::done, this, [this] {
|
||||
handleProcessFinished(d->remoteProcess->errorString());
|
||||
});
|
||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::readyReadStandardOutput,
|
||||
connect(d->remoteProcess.get(), &QtcProcess::readyReadStandardOutput,
|
||||
this, &QtcProcess::readyReadStandardOutput);
|
||||
connect(d->remoteProcess.get(), &QSsh::SshRemoteProcess::readyReadStandardError,
|
||||
connect(d->remoteProcess.get(), &QtcProcess::readyReadStandardError,
|
||||
this, &QtcProcess::readyReadStandardError);
|
||||
d->remoteProcess->start();
|
||||
}
|
||||
|
@@ -200,7 +200,7 @@ void GenericDirectUploadService::runStat(const DeployableFile &file)
|
||||
const QString statCmd = "stat -t " + Utils::ProcessArgs::quoteArgUnix(file.remoteFilePath());
|
||||
SshRemoteProcess * const statProc = connection()->createRemoteProcess(statCmd).release();
|
||||
statProc->setParent(this);
|
||||
connect(statProc, &SshRemoteProcess::finished, this, [this, statProc, state = d->state] {
|
||||
connect(statProc, &QtcProcess::done, this, [this, statProc, state = d->state] {
|
||||
QTC_ASSERT(d->state == state, return);
|
||||
const DeployableFile file = d->getFileForProcess(statProc);
|
||||
QTC_ASSERT(file.isValid(), return);
|
||||
@@ -341,7 +341,7 @@ void GenericDirectUploadService::chmod()
|
||||
SshRemoteProcess * const chmodProc
|
||||
= connection()->createRemoteProcess(command).release();
|
||||
chmodProc->setParent(this);
|
||||
connect(chmodProc, &SshRemoteProcess::finished, this, [this, chmodProc, state = d->state] {
|
||||
connect(chmodProc, &QtcProcess::done, this, [this, chmodProc, state = d->state] {
|
||||
QTC_ASSERT(state == d->state, return);
|
||||
const DeployableFile file = d->getFileForProcess(chmodProc);
|
||||
QTC_ASSERT(file.isValid(), return);
|
||||
|
@@ -38,6 +38,7 @@
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
using namespace QSsh;
|
||||
using namespace Utils;
|
||||
|
||||
namespace RemoteLinux {
|
||||
namespace Internal {
|
||||
@@ -55,7 +56,7 @@ public:
|
||||
SshRemoteProcessPtr process;
|
||||
DeviceUsedPortsGatherer portsGatherer;
|
||||
SftpTransferPtr sftpTransfer;
|
||||
Utils::QtcProcess rsyncProcess;
|
||||
QtcProcess rsyncProcess;
|
||||
State state = Inactive;
|
||||
bool sftpWorks = false;
|
||||
};
|
||||
@@ -126,7 +127,7 @@ void GenericLinuxDeviceTester::handleConnected()
|
||||
QTC_ASSERT(d->state == Connecting, return);
|
||||
|
||||
d->process = d->connection->createRemoteProcess("uname -rsm");
|
||||
connect(d->process.get(), &SshRemoteProcess::finished,
|
||||
connect(d->process.get(), &QtcProcess::done,
|
||||
this, &GenericLinuxDeviceTester::handleProcessFinished);
|
||||
|
||||
emit progressMessage(tr("Checking kernel version..."));
|
||||
@@ -183,7 +184,7 @@ void GenericLinuxDeviceTester::handlePortListReady()
|
||||
emit progressMessage(tr("All specified ports are available.") + QLatin1Char('\n'));
|
||||
} else {
|
||||
QString portList;
|
||||
foreach (const Utils::Port port, d->portsGatherer.usedPorts())
|
||||
foreach (const Port port, d->portsGatherer.usedPorts())
|
||||
portList += QString::number(port.number()) + QLatin1String(", ");
|
||||
portList.remove(portList.count() - 2, 2);
|
||||
emit errorMessage(tr("The following specified ports are currently in use: %1")
|
||||
@@ -221,18 +222,18 @@ void GenericLinuxDeviceTester::handleSftpFinished(const QString &error)
|
||||
void GenericLinuxDeviceTester::testRsync()
|
||||
{
|
||||
emit progressMessage(tr("Checking whether rsync works..."));
|
||||
connect(&d->rsyncProcess, &Utils::QtcProcess::errorOccurred, [this] {
|
||||
connect(&d->rsyncProcess, &QtcProcess::errorOccurred, [this] {
|
||||
if (d->rsyncProcess.error() == QProcess::FailedToStart)
|
||||
handleRsyncFinished();
|
||||
});
|
||||
connect(&d->rsyncProcess, &Utils::QtcProcess::finished, this, [this] {
|
||||
connect(&d->rsyncProcess, &QtcProcess::finished, this, [this] {
|
||||
handleRsyncFinished();
|
||||
});
|
||||
const RsyncCommandLine cmdLine = RsyncDeployStep::rsyncCommand(*d->connection,
|
||||
RsyncDeployStep::defaultFlags());
|
||||
const QStringList args = QStringList(cmdLine.options)
|
||||
<< "-n" << "--exclude=*" << (cmdLine.remoteHostSpec + ":/tmp");
|
||||
d->rsyncProcess.setCommand(Utils::CommandLine("rsync", args));
|
||||
d->rsyncProcess.setCommand(CommandLine("rsync", args));
|
||||
d->rsyncProcess.start();
|
||||
}
|
||||
|
||||
|
@@ -103,7 +103,7 @@ void RsyncDeployService::createRemoteDirectories()
|
||||
remoteDirs.removeDuplicates();
|
||||
m_mkdir = connection()->createRemoteProcess("mkdir -p " +
|
||||
ProcessArgs::createUnixArgs(remoteDirs).toString());
|
||||
connect(m_mkdir.get(), &SshRemoteProcess::finished, this, [this] {
|
||||
connect(m_mkdir.get(), &QtcProcess::done, this, [this] {
|
||||
QString userError;
|
||||
const QString error = m_mkdir->errorString();
|
||||
if (!error.isEmpty())
|
||||
|
@@ -48,6 +48,7 @@
|
||||
#include <cstdlib>
|
||||
|
||||
using namespace QSsh;
|
||||
using namespace Utils;
|
||||
|
||||
class tst_Ssh : public QObject
|
||||
{
|
||||
@@ -76,9 +77,9 @@ void tst_Ssh::initTestCase()
|
||||
if (!SshTest::checkParameters(params))
|
||||
SshTest::printSetupHelp();
|
||||
|
||||
Utils::LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
|
||||
LauncherInterface::setPathToLauncher(qApp->applicationDirPath() + '/'
|
||||
+ QLatin1String(TEST_RELATIVE_LIBEXEC_PATH));
|
||||
Utils::TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
|
||||
TemporaryDirectory::setMasterTemporaryDirectory(QDir::tempPath()
|
||||
+ "/qtc-ssh-autotest-XXXXXX");
|
||||
}
|
||||
|
||||
@@ -118,7 +119,7 @@ void tst_Ssh::errorHandling()
|
||||
params.setUserName(user);
|
||||
params.timeout = 3;
|
||||
params.authenticationType = authType;
|
||||
params.privateKeyFile = Utils::FilePath::fromString(keyFile);
|
||||
params.privateKeyFile = FilePath::fromString(keyFile);
|
||||
SshConnection connection(params);
|
||||
QEventLoop loop;
|
||||
bool disconnected = false;
|
||||
@@ -240,12 +241,12 @@ void tst_Ssh::remoteProcessChannels()
|
||||
SshRemoteProcessPtr echoProcess
|
||||
= connection.createRemoteProcess("printf " + QString::fromUtf8(testString) + " >&2");
|
||||
QEventLoop loop;
|
||||
connect(echoProcess.get(), &SshRemoteProcess::finished, &loop, &QEventLoop::quit);
|
||||
connect(echoProcess.get(), &Utils::QtcProcess::readyReadStandardError,
|
||||
connect(echoProcess.get(), &QtcProcess::done, &loop, &QEventLoop::quit);
|
||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardError,
|
||||
[&remoteData, p = echoProcess.get()] { remoteData += p->readAllStandardError(); });
|
||||
connect(echoProcess.get(), &SshRemoteProcess::readyReadStandardOutput,
|
||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardOutput,
|
||||
[&remoteStdout, p = echoProcess.get()] { remoteStdout += p->readAllStandardOutput(); });
|
||||
connect(echoProcess.get(), &SshRemoteProcess::readyReadStandardError,
|
||||
connect(echoProcess.get(), &QtcProcess::readyReadStandardError,
|
||||
[&remoteStderr] { remoteStderr = testString; });
|
||||
echoProcess->start();
|
||||
QTimer timer;
|
||||
@@ -273,10 +274,10 @@ void tst_Ssh::remoteProcessInput()
|
||||
QVERIFY(waitForConnection(connection));
|
||||
|
||||
SshRemoteProcessPtr catProcess = connection.createRemoteProcess("/bin/cat");
|
||||
catProcess->setProcessMode(Utils::ProcessMode::Writer);
|
||||
catProcess->setProcessMode(ProcessMode::Writer);
|
||||
QEventLoop loop;
|
||||
connect(catProcess.get(), &SshRemoteProcess::started, &loop, &QEventLoop::quit);
|
||||
connect(catProcess.get(), &SshRemoteProcess::finished, &loop, &QEventLoop::quit);
|
||||
connect(catProcess.get(), &QtcProcess::started, &loop, &QEventLoop::quit);
|
||||
connect(catProcess.get(), &QtcProcess::done, &loop, &QEventLoop::quit);
|
||||
QTimer timer;
|
||||
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
|
||||
timer.setSingleShot(true);
|
||||
@@ -289,7 +290,7 @@ void tst_Ssh::remoteProcessInput()
|
||||
QVERIFY(catProcess->isRunning());
|
||||
|
||||
static QString testString = "x\r\n";
|
||||
connect(catProcess.get(), &Utils::QtcProcess::readyReadStandardOutput, &loop, &QEventLoop::quit);
|
||||
connect(catProcess.get(), &QtcProcess::readyReadStandardOutput, &loop, &QEventLoop::quit);
|
||||
|
||||
catProcess->write(testString.toUtf8());
|
||||
timer.start();
|
||||
@@ -460,7 +461,7 @@ void tst_Ssh::sftp()
|
||||
QVERIFY(success);
|
||||
|
||||
// The same again, with a non-interactive download.
|
||||
FilesToTransfer filesToDownload = Utils::transform(filesToUpload, [&](const FileToTransfer &fileToUpload) {
|
||||
const FilesToTransfer filesToDownload = transform(filesToUpload, [&](const FileToTransfer &fileToUpload) {
|
||||
return FileToTransfer(fileToUpload.targetFile,
|
||||
getDownloadFilePath(dir2ForFilesToDownload,
|
||||
QFileInfo(fileToUpload.sourceFile).fileName()));
|
||||
@@ -574,7 +575,7 @@ void tst_Ssh::sftp()
|
||||
|
||||
void tst_Ssh::cleanupTestCase()
|
||||
{
|
||||
Utils::Singleton::deleteAll();
|
||||
Singleton::deleteAll();
|
||||
}
|
||||
|
||||
bool tst_Ssh::waitForConnection(SshConnection &connection)
|
||||
|
@@ -35,6 +35,7 @@
|
||||
#include <iostream>
|
||||
|
||||
using namespace QSsh;
|
||||
using namespace Utils;
|
||||
|
||||
Shell::Shell(const SshConnectionParameters ¶meters, QObject *parent)
|
||||
: QObject(parent),
|
||||
@@ -70,12 +71,12 @@ void Shell::handleConnectionError()
|
||||
void Shell::handleConnected()
|
||||
{
|
||||
m_shell = m_connection->createRemoteShell();
|
||||
connect(m_shell.get(), &SshRemoteProcess::started, this, &Shell::handleShellStarted);
|
||||
connect(m_shell.get(), &SshRemoteProcess::readyReadStandardOutput,
|
||||
connect(m_shell.get(), &QtcProcess::started, this, &Shell::handleShellStarted);
|
||||
connect(m_shell.get(), &QtcProcess::readyReadStandardOutput,
|
||||
this, &Shell::handleRemoteStdout);
|
||||
connect(m_shell.get(), &SshRemoteProcess::readyReadStandardError,
|
||||
connect(m_shell.get(), &QtcProcess::readyReadStandardError,
|
||||
this, &Shell::handleRemoteStderr);
|
||||
connect(m_shell.get(), &SshRemoteProcess::finished, this, &Shell::handleChannelClosed);
|
||||
connect(m_shell.get(), &QtcProcess::done, this, &Shell::handleChannelClosed);
|
||||
m_shell->start();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user