forked from qt-creator/qt-creator
SSH: Pass remote command as QString
The old implementation sent the command over the wire as-is, so we declared it as a QByteArray and let the caller choose the encoding. This doesn't make sense anymore, as the command is now passed to an external process as a QString anyway. Change-Id: Ib84bc0f871db2b45b93f71d924c4177cc28d3bb0 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -309,7 +309,7 @@ SshConnection::~SshConnection()
|
||||
delete d;
|
||||
}
|
||||
|
||||
SshRemoteProcessPtr SshConnection::createRemoteProcess(const QByteArray &command)
|
||||
SshRemoteProcessPtr SshConnection::createRemoteProcess(const QString &command)
|
||||
{
|
||||
QTC_ASSERT(state() == Connected, return SshRemoteProcessPtr());
|
||||
return SshRemoteProcessPtr(new SshRemoteProcess(command, d->connectionArgs()));
|
||||
@@ -317,7 +317,7 @@ SshRemoteProcessPtr SshConnection::createRemoteProcess(const QByteArray &command
|
||||
|
||||
SshRemoteProcessPtr SshConnection::createRemoteShell()
|
||||
{
|
||||
return createRemoteProcess(QByteArray());
|
||||
return createRemoteProcess({});
|
||||
}
|
||||
|
||||
SftpTransferPtr SshConnection::createUpload(const FilesToTransfer &files,
|
||||
|
@@ -111,7 +111,7 @@ public:
|
||||
bool sharingEnabled() const;
|
||||
~SshConnection();
|
||||
|
||||
SshRemoteProcessPtr createRemoteProcess(const QByteArray &command);
|
||||
SshRemoteProcessPtr createRemoteProcess(const QString &command);
|
||||
SshRemoteProcessPtr createRemoteShell();
|
||||
SftpTransferPtr createUpload(const FilesToTransfer &files,
|
||||
FileTransferErrorHandling errorHandlingMode);
|
||||
|
@@ -54,13 +54,13 @@ using namespace Internal;
|
||||
|
||||
struct SshRemoteProcess::SshRemoteProcessPrivate
|
||||
{
|
||||
QByteArray remoteCommand;
|
||||
QString remoteCommand;
|
||||
QStringList connectionArgs;
|
||||
QString displayName;
|
||||
bool useTerminal = false;
|
||||
};
|
||||
|
||||
SshRemoteProcess::SshRemoteProcess(const QByteArray &command, const QStringList &connectionArgs)
|
||||
SshRemoteProcess::SshRemoteProcess(const QString &command, const QStringList &connectionArgs)
|
||||
: d(new SshRemoteProcessPrivate)
|
||||
{
|
||||
d->remoteCommand = command;
|
||||
@@ -127,7 +127,7 @@ QStringList SshRemoteProcess::fullLocalCommandLine() const
|
||||
if (!d->displayName.isEmpty())
|
||||
args.prepend("-X");
|
||||
if (!d->remoteCommand.isEmpty())
|
||||
args << QLatin1String(d->remoteCommand);
|
||||
args << d->remoteCommand;
|
||||
args.prepend(SshSettings::sshFilePath().toString());
|
||||
return args;
|
||||
}
|
||||
|
@@ -30,10 +30,6 @@
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
class QByteArray;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace QSsh {
|
||||
class SshConnection;
|
||||
|
||||
@@ -56,7 +52,7 @@ signals:
|
||||
void done(const QString &error);
|
||||
|
||||
private:
|
||||
SshRemoteProcess(const QByteArray &command, const QStringList &connectionArgs);
|
||||
SshRemoteProcess(const QString &command, const QStringList &connectionArgs);
|
||||
void doStart();
|
||||
|
||||
struct SshRemoteProcessPrivate;
|
||||
|
@@ -50,7 +50,7 @@ public:
|
||||
SshRemoteProcessPtr m_process;
|
||||
SshConnection *m_connection;
|
||||
bool m_runInTerminal;
|
||||
QByteArray m_command;
|
||||
QString m_command;
|
||||
QString m_lastConnectionErrorString;
|
||||
QProcess::ExitStatus m_exitStatus;
|
||||
QByteArray m_stdout;
|
||||
@@ -76,8 +76,7 @@ SshRemoteProcessRunner::~SshRemoteProcessRunner()
|
||||
delete d;
|
||||
}
|
||||
|
||||
void SshRemoteProcessRunner::run(const QByteArray &command,
|
||||
const SshConnectionParameters &sshParams)
|
||||
void SshRemoteProcessRunner::run(const QString &command, const SshConnectionParameters &sshParams)
|
||||
{
|
||||
QTC_ASSERT(d->m_state == Inactive, return);
|
||||
|
||||
@@ -85,14 +84,14 @@ void SshRemoteProcessRunner::run(const QByteArray &command,
|
||||
runInternal(command, sshParams);
|
||||
}
|
||||
|
||||
void SshRemoteProcessRunner::runInTerminal(const QByteArray &command,
|
||||
void SshRemoteProcessRunner::runInTerminal(const QString &command,
|
||||
const SshConnectionParameters &sshParams)
|
||||
{
|
||||
d->m_runInTerminal = true;
|
||||
runInternal(command, sshParams);
|
||||
}
|
||||
|
||||
void SshRemoteProcessRunner::runInternal(const QByteArray &command,
|
||||
void SshRemoteProcessRunner::runInternal(const QString &command,
|
||||
const SshConnectionParameters &sshParams)
|
||||
{
|
||||
setState(Connecting);
|
||||
@@ -197,7 +196,7 @@ void SshRemoteProcessRunner::setState(int newState)
|
||||
}
|
||||
}
|
||||
|
||||
QByteArray SshRemoteProcessRunner::command() const { return d->m_command; }
|
||||
QString SshRemoteProcessRunner::command() const { return d->m_command; }
|
||||
QString SshRemoteProcessRunner::lastConnectionErrorString() const {
|
||||
return d->m_lastConnectionErrorString;
|
||||
}
|
||||
|
@@ -39,9 +39,9 @@ public:
|
||||
SshRemoteProcessRunner(QObject *parent = 0);
|
||||
~SshRemoteProcessRunner();
|
||||
|
||||
void run(const QByteArray &command, const SshConnectionParameters &sshParams);
|
||||
void runInTerminal(const QByteArray &command, const SshConnectionParameters &sshParams);
|
||||
QByteArray command() const;
|
||||
void run(const QString &command, const SshConnectionParameters &sshParams);
|
||||
void runInTerminal(const QString &command, const SshConnectionParameters &sshParams);
|
||||
QString command() const;
|
||||
|
||||
QString lastConnectionErrorString() const;
|
||||
|
||||
@@ -69,7 +69,7 @@ private:
|
||||
void handleProcessFinished(const QString &error);
|
||||
void handleStdout();
|
||||
void handleStderr();
|
||||
void runInternal(const QByteArray &command, const QSsh::SshConnectionParameters &sshParams);
|
||||
void runInternal(const QString &command, const QSsh::SshConnectionParameters &sshParams);
|
||||
void setState(int newState);
|
||||
|
||||
Internal::SshRemoteProcessRunnerPrivate * const d;
|
||||
|
@@ -188,7 +188,7 @@ void SshDeviceProcess::handleConnected()
|
||||
|
||||
d->process = runInTerminal() && d->runnable.executable.isEmpty()
|
||||
? d->connection->createRemoteShell()
|
||||
: d->connection->createRemoteProcess(fullCommandLine(d->runnable).toUtf8());
|
||||
: d->connection->createRemoteProcess(fullCommandLine(d->runnable));
|
||||
const QString display = d->displayName();
|
||||
if (!display.isEmpty())
|
||||
d->process->requestX11Forwarding(display);
|
||||
|
@@ -54,7 +54,7 @@ void SshDeviceProcessList::doUpdate()
|
||||
this, &SshDeviceProcessList::handleConnectionError);
|
||||
connect(&d->process, &SshRemoteProcessRunner::processClosed,
|
||||
this, &SshDeviceProcessList::handleListProcessFinished);
|
||||
d->process.run(listProcessesCommandLine().toUtf8(), device()->sshParameters());
|
||||
d->process.run(listProcessesCommandLine(), device()->sshParameters());
|
||||
}
|
||||
|
||||
void SshDeviceProcessList::doKillProcess(const DeviceProcessItem &process)
|
||||
|
@@ -292,12 +292,9 @@ void QnxDeployQtLibrariesDialog::checkRemoteDirectoryExistance()
|
||||
QTC_CHECK(m_state == Inactive);
|
||||
|
||||
m_state = CheckingRemoteDirectory;
|
||||
|
||||
m_ui->deployLogWindow->appendPlainText(tr("Checking existence of \"%1\"")
|
||||
.arg(fullRemoteDirectory()));
|
||||
|
||||
const QByteArray cmd = "test -d " + fullRemoteDirectory().toLatin1();
|
||||
m_processRunner->run(cmd, m_device->sshParameters());
|
||||
m_processRunner->run("test -d " + fullRemoteDirectory(), m_device->sshParameters());
|
||||
}
|
||||
|
||||
void QnxDeployQtLibrariesDialog::removeRemoteDirectory()
|
||||
@@ -305,11 +302,8 @@ void QnxDeployQtLibrariesDialog::removeRemoteDirectory()
|
||||
QTC_CHECK(m_state == CheckingRemoteDirectory);
|
||||
|
||||
m_state = RemovingRemoteDirectory;
|
||||
|
||||
m_ui->deployLogWindow->appendPlainText(tr("Removing \"%1\"").arg(fullRemoteDirectory()));
|
||||
|
||||
const QByteArray cmd = "rm -rf " + fullRemoteDirectory().toLatin1();
|
||||
m_processRunner->run(cmd, m_device->sshParameters());
|
||||
m_processRunner->run("rm -rf " + fullRemoteDirectory(), m_device->sshParameters());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
@@ -113,8 +113,7 @@ void QnxDeviceTester::handleGenericTestFinished(TestResult result)
|
||||
m_state = VarRunTest;
|
||||
emit progressMessage(tr("Checking that files can be created in /var/run..."));
|
||||
m_processRunner->run(QStringLiteral("rm %1 > /dev/null 2>&1; echo ABC > %1 && rm %1")
|
||||
.arg("/var/run/qtc_xxxx.pid")
|
||||
.toLatin1(),
|
||||
.arg("/var/run/qtc_xxxx.pid"),
|
||||
m_deviceConfiguration->sshParameters());
|
||||
}
|
||||
|
||||
@@ -189,7 +188,7 @@ void QnxDeviceTester::testNextCommand()
|
||||
QString command = m_commandsToTest[m_currentCommandIndex];
|
||||
emit progressMessage(tr("Checking for %1...").arg(command));
|
||||
|
||||
m_processRunner->run("command -v " + command.toLatin1(), m_deviceConfiguration->sshParameters());
|
||||
m_processRunner->run("command -v " + command, m_deviceConfiguration->sshParameters());
|
||||
}
|
||||
|
||||
void QnxDeviceTester::setFinished()
|
||||
|
@@ -238,8 +238,7 @@ void GenericDirectUploadService::queryFiles()
|
||||
continue;
|
||||
}
|
||||
// We'd like to use --format=%Y, but it's not supported by busybox.
|
||||
const QByteArray statCmd = "stat -t "
|
||||
+ Utils::QtcProcess::quoteArgUnix(file.remoteFilePath()).toUtf8();
|
||||
const QString statCmd = "stat -t " + Utils::QtcProcess::quoteArgUnix(file.remoteFilePath());
|
||||
SshRemoteProcess * const statProc = connection()->createRemoteProcess(statCmd).release();
|
||||
statProc->setParent(this);
|
||||
connect(statProc, &SshRemoteProcess::done, this,
|
||||
@@ -328,7 +327,7 @@ void GenericDirectUploadService::chmod()
|
||||
const QString command = QLatin1String("chmod a+x ")
|
||||
+ Utils::QtcProcess::quoteArgUnix(f.remoteFilePath());
|
||||
SshRemoteProcess * const chmodProc
|
||||
= connection()->createRemoteProcess(command.toUtf8()).release();
|
||||
= connection()->createRemoteProcess(command).release();
|
||||
chmodProc->setParent(this);
|
||||
connect(chmodProc, &SshRemoteProcess::done, this,
|
||||
[this, chmodProc, state = d->state](const QString &error) {
|
||||
|
@@ -122,7 +122,7 @@ void RemoteLinuxCheckForFreeDiskSpaceService::doDeploy()
|
||||
this, &RemoteLinuxCheckForFreeDiskSpaceService::handleStdErr);
|
||||
const QString command = QString::fromLatin1("df -k %1 |tail -n 1 |sed 's/ */ /g' "
|
||||
"|cut -d ' ' -f 4").arg(d->pathToCheck);
|
||||
d->processRunner->run(command.toUtf8(), deviceConfiguration()->sshParameters());
|
||||
d->processRunner->run(command, deviceConfiguration()->sshParameters());
|
||||
}
|
||||
|
||||
void RemoteLinuxCheckForFreeDiskSpaceService::stopDeployment()
|
||||
|
@@ -91,7 +91,7 @@ void RemoteLinuxCustomCommandDeployService::doDeploy()
|
||||
|
||||
emit progressMessage(tr("Starting remote command \"%1\"...").arg(d->commandLine));
|
||||
d->state = Running;
|
||||
d->runner->run(d->commandLine.toUtf8(), deviceConfiguration()->sshParameters());
|
||||
d->runner->run(d->commandLine, deviceConfiguration()->sshParameters());
|
||||
}
|
||||
|
||||
void RemoteLinuxCustomCommandDeployService::stopDeployment()
|
||||
|
@@ -76,7 +76,7 @@ void AbstractRemoteLinuxPackageInstaller::installPackage(const IDevice::ConstPtr
|
||||
QString cmdLine = installCommandLine(packageFilePath);
|
||||
if (removePackageFile)
|
||||
cmdLine += QLatin1String(" && (rm ") + packageFilePath + QLatin1String(" || :)");
|
||||
d->installer->run(cmdLine.toUtf8(), deviceConfig->sshParameters());
|
||||
d->installer->run(cmdLine, deviceConfig->sshParameters());
|
||||
d->isRunning = true;
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ void AbstractRemoteLinuxPackageInstaller::cancelInstallation()
|
||||
|
||||
if (!d->killProcess)
|
||||
d->killProcess = new SshRemoteProcessRunner(this);
|
||||
d->killProcess->run(cancelInstallationCommandLine().toUtf8(), d->deviceConfig->sshParameters());
|
||||
d->killProcess->run(cancelInstallationCommandLine(), d->deviceConfig->sshParameters());
|
||||
setFinished();
|
||||
}
|
||||
|
||||
|
@@ -60,7 +60,7 @@ void RemoteLinuxSignalOperation::run(const QString &command)
|
||||
this, &RemoteLinuxSignalOperation::runnerProcessFinished);
|
||||
connect(m_runner, &QSsh::SshRemoteProcessRunner::connectionError,
|
||||
this, &RemoteLinuxSignalOperation::runnerConnectionError);
|
||||
m_runner->run(command.toLatin1(), m_sshParameters);
|
||||
m_runner->run(command, m_sshParameters);
|
||||
}
|
||||
|
||||
void RemoteLinuxSignalOperation::finish()
|
||||
|
@@ -101,7 +101,7 @@ void RsyncDeployService::createRemoteDirectories()
|
||||
remoteDirs.sort();
|
||||
remoteDirs.removeDuplicates();
|
||||
m_mkdir = connection()->createRemoteProcess("mkdir -p " + QtcProcess::Arguments
|
||||
::createUnixArgs(remoteDirs).toString().toUtf8());
|
||||
::createUnixArgs(remoteDirs).toString());
|
||||
connect(m_mkdir.get(), &SshRemoteProcess::done, this, [this](const QString &error) {
|
||||
QString userError;
|
||||
if (!error.isEmpty())
|
||||
|
@@ -67,9 +67,10 @@ void SshKeyDeployer::deployPublicKey(const SshConnectionParameters &sshParams,
|
||||
this, &SshKeyDeployer::handleConnectionFailure);
|
||||
connect(&d->deployProcess, &SshRemoteProcessRunner::processClosed,
|
||||
this, &SshKeyDeployer::handleKeyUploadFinished);
|
||||
const QByteArray command = "test -d .ssh "
|
||||
const QString command = "test -d .ssh "
|
||||
"|| mkdir .ssh && chmod 0700 .ssh && echo '"
|
||||
+ reader.data() + "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
||||
+ QString::fromLocal8Bit(reader.data())
|
||||
+ "' >> .ssh/authorized_keys && chmod 0600 .ssh/authorized_keys";
|
||||
d->deployProcess.run(command, sshParams);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user