From ce7b99bc8887af995e1d34f00ba1831bd08c7d97 Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 20 Apr 2023 17:59:26 +0200 Subject: [PATCH] RemoteLinux: Honor working directory setting again Fixes: QTCREATORBUG-28900 Change-Id: I163877a749f378b2aa7579c1985e58f8a9d87e2c Reviewed-by: Jarek Kobus --- .../remotelinux/filesystemaccess_test.cpp | 16 ++++++++++++++++ src/plugins/remotelinux/filesystemaccess_test.h | 1 + src/plugins/remotelinux/linuxdevice.cpp | 14 +++++++++----- 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/plugins/remotelinux/filesystemaccess_test.cpp b/src/plugins/remotelinux/filesystemaccess_test.cpp index 13e46619ff3..edcb8d4d01c 100644 --- a/src/plugins/remotelinux/filesystemaccess_test.cpp +++ b/src/plugins/remotelinux/filesystemaccess_test.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -181,6 +182,21 @@ void FileSystemAccessTest::testCreateRemoteFile() QVERIFY(!testFilePath.exists()); } +void FileSystemAccessTest::testWorkingDirectory() +{ + const FilePath dir = baseFilePath() / "testdir with space and 'various' \"quotes\" here"; + QVERIFY(dir.ensureWritableDir()); + QtcProcess proc; + proc.setCommand({"pwd", {}}); + proc.setWorkingDirectory(dir); + proc.start(); + QVERIFY(proc.waitForFinished()); + const QString out = proc.readAllStandardOutput().trimmed(); + QCOMPARE(out, dir.path()); + const QString err = proc.readAllStandardOutput(); + QVERIFY(err.isEmpty()); +} + void FileSystemAccessTest::testDirStatus() { FilePath filePath = baseFilePath(); diff --git a/src/plugins/remotelinux/filesystemaccess_test.h b/src/plugins/remotelinux/filesystemaccess_test.h index 84321db6ce8..087eabbcad9 100644 --- a/src/plugins/remotelinux/filesystemaccess_test.h +++ b/src/plugins/remotelinux/filesystemaccess_test.h @@ -24,6 +24,7 @@ private slots: void testCreateRemoteFile_data(); void testCreateRemoteFile(); + void testWorkingDirectory(); void testDirStatus(); void testBytesAvailable(); void testFileActions(); diff --git a/src/plugins/remotelinux/linuxdevice.cpp b/src/plugins/remotelinux/linuxdevice.cpp index 97b6412e6c2..583a6bdeaf5 100644 --- a/src/plugins/remotelinux/linuxdevice.cpp +++ b/src/plugins/remotelinux/linuxdevice.cpp @@ -612,13 +612,17 @@ void SshProcessInterfacePrivate::start() cmd.addArg("-tt"); const CommandLine full = q->m_setup.m_commandLine; - if (!full.isEmpty()) { + if (!full.isEmpty()) { // Empty is ok in case of opening a terminal. + CommandLine inner; + const QString wd = q->m_setup.m_workingDirectory.path(); + if (!wd.isEmpty()) + inner.addCommandLineWithAnd({"cd", {wd}}); if (!useTerminal) { - // Empty is ok in case of opening a terminal. - cmd.addArgs(QString("echo ") + s_pidMarker + "\\$\\$" + s_pidMarker + " \\&\\& ", - CommandLine::Raw); + const QString pidArg = QString("%1\\$\\$%1").arg(QString::fromLatin1(s_pidMarker)); + inner.addCommandLineWithAnd({"echo", pidArg, CommandLine::Raw}); } - cmd.addCommandLineAsArgs(full, CommandLine::Raw); + inner.addCommandLineWithAnd(full); + cmd.addCommandLineAsSingleArg(inner); } m_process.setProcessImpl(q->m_setup.m_processImpl);