QtcProcess: Get rid of useTerminal

Remove SshRemoteProcessRunner::runInTerminal() method,
it wasn't used anywhere (just in test).
Remove QtcProcess::useTerminal, as process should be
created in TerminalOn mode when there is a need for terminal.
Add a parameter to
SshRemoteProcess::fullLocalCommandLine(bool inTerminal)
as this may still be needed when running application
through ssh from terminal (ssh -tt option).

Change-Id: I71911082fcca190b82a1106a2ca1ca48dc5d4c79
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-01-28 12:08:09 +01:00
parent 0c0bd8777a
commit 95a9b22f6f
8 changed files with 8 additions and 47 deletions

View File

@@ -89,13 +89,13 @@ void SshRemoteProcess::requestX11Forwarding(const QString &displayName)
m_displayName = displayName;
}
Utils::CommandLine SshRemoteProcess::fullLocalCommandLine() const
Utils::CommandLine SshRemoteProcess::fullLocalCommandLine(bool inTerminal) const
{
Utils::CommandLine cmd{SshSettings::sshFilePath()};
if (!m_displayName.isEmpty())
cmd.addArg("-X");
if (useTerminal())
if (inTerminal)
cmd.addArg("-tt");
cmd.addArg("-q");

View File

@@ -43,7 +43,7 @@ public:
void requestX11Forwarding(const QString &displayName);
void start();
Utils::CommandLine fullLocalCommandLine() const;
Utils::CommandLine fullLocalCommandLine(bool inTerminal = false) const;
signals:
void done(const QString &error);

View File

@@ -49,7 +49,6 @@ public:
SshRemoteProcessPtr m_process;
SshConnection *m_connection;
bool m_runInTerminal;
QString m_command;
QString m_lastConnectionErrorString;
QProcess::ExitStatus m_exitStatus;
@@ -80,14 +79,6 @@ void SshRemoteProcessRunner::run(const QString &command, const SshConnectionPara
{
QTC_ASSERT(d->m_state == Inactive, return);
d->m_runInTerminal = false;
runInternal(command, sshParams);
}
void SshRemoteProcessRunner::runInTerminal(const QString &command,
const SshConnectionParameters &sshParams)
{
d->m_runInTerminal = true;
runInternal(command, sshParams);
}
@@ -128,7 +119,6 @@ void SshRemoteProcessRunner::handleConnected()
this, &SshRemoteProcessRunner::handleStdout);
connect(d->m_process.get(), &SshRemoteProcess::readyReadStandardError,
this, &SshRemoteProcessRunner::handleStderr);
d->m_process->setUseTerminal(d->m_runInTerminal);
d->m_process->start();
}

View File

@@ -40,7 +40,6 @@ public:
~SshRemoteProcessRunner();
void run(const QString &command, const SshConnectionParameters &sshParams);
void runInTerminal(const QString &command, const SshConnectionParameters &sshParams);
QString command() const;
QString lastConnectionErrorString() const;

View File

@@ -260,9 +260,6 @@ public:
void setUnixTerminalDisabled() { m_unixTerminalDisabled = true; }
bool isUnixTerminalDisabled() const { return m_unixTerminalDisabled; }
void setUseTerminal(bool on) { m_useTerminal = on; }
bool useTerminal() const { return m_useTerminal; }
void setAbortOnMetaChars(bool abort) { m_abortOnMetaChars = abort; }
bool isAbortOnMetaChars() const { return m_abortOnMetaChars; }
@@ -289,7 +286,6 @@ private:
QString m_nativeArguments;
bool m_lowPriority = false;
bool m_unixTerminalDisabled = false;
bool m_useTerminal = false;
bool m_abortOnMetaChars = true;
bool m_runAsRoot = false;
};
@@ -908,16 +904,6 @@ void QtcProcess::setDisableUnixTerminal()
d->m_process->setUnixTerminalDisabled();
}
void QtcProcess::setUseTerminal(bool on)
{
d->m_process->setUseTerminal(on);
}
bool QtcProcess::useTerminal() const
{
return d->m_process->useTerminal();
}
void QtcProcess::setAbortOnMetaChars(bool abort)
{
d->m_process->setAbortOnMetaChars(abort);

View File

@@ -115,9 +115,6 @@ public:
void setDisableUnixTerminal();
void setRunAsRoot(bool on);
void setUseTerminal(bool on);
bool useTerminal() const;
void setAbortOnMetaChars(bool abort);
void start();

View File

@@ -192,7 +192,6 @@ void SshDeviceProcess::handleConnected()
if (!display.isEmpty())
d->process->requestX11Forwarding(display);
if (runInTerminal()) {
d->process->setUseTerminal(true);
connect(&d->consoleProcess, &QtcProcess::errorOccurred,
this, &DeviceProcess::error);
connect(&d->consoleProcess, &QtcProcess::started,
@@ -200,7 +199,7 @@ void SshDeviceProcess::handleConnected()
connect(&d->consoleProcess, &QtcProcess::finished,
this, [this] { handleProcessFinished(d->consoleProcess.errorString()); });
d->consoleProcess.setAbortOnMetaChars(false);
d->consoleProcess.setCommand(d->process->fullLocalCommandLine());
d->consoleProcess.setCommand(d->process->fullLocalCommandLine(true));
d->consoleProcess.start();
} else {
connect(d->process.get(), &QSsh::SshRemoteProcess::started,

View File

@@ -216,20 +216,14 @@ void tst_Ssh::pristineConnectionObject()
void tst_Ssh::remoteProcess_data()
{
QTest::addColumn<QByteArray>("commandLine");
QTest::addColumn<bool>("useTerminal");
QTest::addColumn<bool>("isBlocking");
QTest::addColumn<bool>("successExpected");
QTest::addColumn<bool>("stdoutExpected");
QTest::addColumn<bool>("stderrExpected");
QTest::newRow("normal command")
<< QByteArray("ls -a /tmp") << false << false << true << true << false;
QTest::newRow("failing command")
<< QByteArray("top -n 1") << false << false << false << false << true;
QTest::newRow("blocking command")
<< QByteArray("/bin/sleep 100") << false << true << false << false << false;
QTest::newRow("terminal command")
<< QByteArray("top -n 1") << true << false << true << true << false;
QTest::newRow("normal cmd") << QByteArray("ls -a /tmp") << false << true << true << false;
QTest::newRow("failing cmd") << QByteArray("top -n 1") << false << false << false << true;
QTest::newRow("blocking cmd") << QByteArray("sleep 100") << true << false << false << false;
}
void tst_Ssh::remoteProcess()
@@ -238,7 +232,6 @@ void tst_Ssh::remoteProcess()
CHECK_PARAMS(params);
QFETCH(QByteArray, commandLine);
QFETCH(bool, useTerminal);
QFETCH(bool, isBlocking);
QFETCH(bool, successExpected);
QFETCH(bool, stdoutExpected);
@@ -255,10 +248,7 @@ void tst_Ssh::remoteProcess()
[&remoteStdout, &runner] { remoteStdout += runner.readAllStandardOutput(); });
connect(&runner, &SshRemoteProcessRunner::readyReadStandardError,
[&remoteStderr, &runner] { remoteStderr += runner.readAllStandardError(); });
if (useTerminal)
runner.runInTerminal(QString::fromUtf8(commandLine), params);
else
runner.run(QString::fromUtf8(commandLine), params);
runner.run(QString::fromUtf8(commandLine), params);
QTimer timer;
QObject::connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
timer.setSingleShot(true);