From 2591d02fef9392dcb489725dde29d0fc0ff481d7 Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 4 Jun 2019 15:59:30 +0200 Subject: [PATCH] RemoteLinux: Use Util::CommandLine to construct device process commands Change-Id: I194b5225f56cabd92e1de7d3df2e74b515aa476e Reviewed-by: Christian Kandeler --- .../remotelinux/linuxdeviceprocess.cpp | 54 +++++++++---------- src/plugins/remotelinux/linuxdeviceprocess.h | 2 +- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/plugins/remotelinux/linuxdeviceprocess.cpp b/src/plugins/remotelinux/linuxdeviceprocess.cpp index 00bd28b6e56..ca08b44ec90 100644 --- a/src/plugins/remotelinux/linuxdeviceprocess.cpp +++ b/src/plugins/remotelinux/linuxdeviceprocess.cpp @@ -28,15 +28,12 @@ #include #include -#include using namespace ProjectExplorer; using namespace Utils; namespace RemoteLinux { -static QString quote(const QString &s) { return Utils::QtcProcess::quoteArgUnix(s); } - LinuxDeviceProcess::LinuxDeviceProcess(const QSharedPointer &device, QObject *parent) : ProjectExplorer::SshDeviceProcess(device, parent), m_processId(0) @@ -78,42 +75,41 @@ qint64 LinuxDeviceProcess::processId() const QString LinuxDeviceProcess::fullCommandLine(const Runnable &runnable) const { - const Environment env = runnable.environment; + CommandLine cmd; + + for (const QString &filePath : rcFilesToSource()) { + cmd.addArgs({"test", "-f", filePath}); + cmd.addArgs("&&"); + cmd.addArgs({".", filePath}); + cmd.addArgs(";"); + } - QString fullCommandLine; - foreach (const QString &filePath, rcFilesToSource()) - fullCommandLine += QString::fromLatin1("test -f %1 && . %1;").arg(filePath); if (!runnable.workingDirectory.isEmpty()) { - fullCommandLine.append(QLatin1String("cd ")).append(quote(runnable.workingDirectory)) - .append(QLatin1String(" && ")); - } - QString envString; - for (auto it = env.constBegin(); it != env.constEnd(); ++it) { - if (!envString.isEmpty()) - envString += QLatin1Char(' '); - envString.append(env.key(it)).append(QLatin1String("='")).append(env.value(it)) - .append(QLatin1Char('\'')); + cmd.addArgs({"cd", runnable.workingDirectory}); + cmd.addArgs("&&"); } + if (!runInTerminal()) - fullCommandLine.append("echo $$ && "); - if (!envString.isEmpty()) - fullCommandLine.append(envString); + cmd.addArgs("echo $$ && "); + + const Environment &env = runnable.environment; + for (auto it = env.constBegin(); it != env.constEnd(); ++it) + cmd.addArgs(env.key(it) + "='" + env.value(it) + '\''); + if (!runInTerminal()) - fullCommandLine.append(" exec"); - fullCommandLine.append(' '); - fullCommandLine.append(quote(runnable.executable)); - if (!runnable.commandLineArguments.isEmpty()) { - fullCommandLine.append(QLatin1Char(' ')); - fullCommandLine.append(runnable.commandLineArguments); - } - return fullCommandLine; + cmd.addArg("exec"); + + cmd.addArg(runnable.executable); + cmd.addArgs(runnable.commandLineArguments); + + return cmd.arguments(); } -QStringList LinuxDeviceProcess::rcFilesToSource() const +const QStringList LinuxDeviceProcess::rcFilesToSource() const { if (!m_rcFilesToSource.isEmpty()) return m_rcFilesToSource; - return QStringList() << QLatin1String("/etc/profile") << QLatin1String("$HOME/.profile"); + return {"/etc/profile", "$HOME/.profile"}; } } // namespace RemoteLinux diff --git a/src/plugins/remotelinux/linuxdeviceprocess.h b/src/plugins/remotelinux/linuxdeviceprocess.h index 4b565029cc8..b9172220180 100644 --- a/src/plugins/remotelinux/linuxdeviceprocess.h +++ b/src/plugins/remotelinux/linuxdeviceprocess.h @@ -49,7 +49,7 @@ private: QString fullCommandLine(const ProjectExplorer::Runnable &) const override; qint64 processId() const override; - QStringList rcFilesToSource() const; + const QStringList rcFilesToSource() const; QStringList m_rcFilesToSource; QByteArray m_processIdString;