From 508dd23de46ab0d101bbf58c875c2b3ad8c37824 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 18 Oct 2022 09:55:58 +0200 Subject: [PATCH] Utils: Use Linux quoting in UnixDeviceFileAccess This forces all commands in UnixDeviceFileAccess to use Unix style quoting of commands. Change-Id: Ia8a2691b7058789a7afa95a9bb87f155a36cf680 Reviewed-by: David Schulz --- src/libs/utils/devicefileaccess.cpp | 54 ++++++++++++++--------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/libs/utils/devicefileaccess.cpp b/src/libs/utils/devicefileaccess.cpp index 956b524e724..6123cd6751c 100644 --- a/src/libs/utils/devicefileaccess.cpp +++ b/src/libs/utils/devicefileaccess.cpp @@ -629,72 +629,72 @@ bool UnixDeviceFileAccess::runInShellSuccess(const CommandLine &cmdLine, bool UnixDeviceFileAccess::isExecutableFile(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-x", path}}); + return runInShellSuccess({"test", {"-x", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isReadableFile(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-r", path, "-a", "-f", path}}); + return runInShellSuccess({"test", {"-r", path, "-a", "-f", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isWritableFile(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-w", path, "-a", "-f", path}}); + return runInShellSuccess({"test", {"-w", path, "-a", "-f", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isReadableDirectory(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-r", path, "-a", "-d", path}}); + return runInShellSuccess({"test", {"-r", path, "-a", "-d", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isWritableDirectory(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-w", path, "-a", "-d", path}}); + return runInShellSuccess({"test", {"-w", path, "-a", "-d", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isFile(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-f", path}}); + return runInShellSuccess({"test", {"-f", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isDirectory(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-d", path}}); + return runInShellSuccess({"test", {"-d", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::isSymLink(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-h", path}}); + return runInShellSuccess({"test", {"-h", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::ensureExistingFile(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"touch", {path}}); + return runInShellSuccess({"touch", {path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::createDirectory(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"mkdir", {"-p", path}}); + return runInShellSuccess({"mkdir", {"-p", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::exists(const FilePath &filePath) const { const QString path = filePath.path(); - return runInShellSuccess({"test", {"-e", path}}); + return runInShellSuccess({"test", {"-e", path}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::removeFile(const FilePath &filePath) const { - return runInShellSuccess({"rm", {filePath.path()}}); + return runInShellSuccess({"rm", {filePath.path()}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString *error) const @@ -710,7 +710,7 @@ bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString * levelsNeeded = 2; QTC_ASSERT(path.count('/') >= levelsNeeded, return false); - RunResult result = runInShell({"rm", {"-rf", "--", path}}); + RunResult result = runInShell({"rm", {"-rf", "--", path}, OsType::OsTypeLinux}); if (error) *error = QString::fromUtf8(result.stdErr); return result.exitCode == 0; @@ -718,17 +718,17 @@ bool UnixDeviceFileAccess::removeRecursively(const FilePath &filePath, QString * bool UnixDeviceFileAccess::copyFile(const FilePath &filePath, const FilePath &target) const { - return runInShellSuccess({"cp", {filePath.path(), target.path()}}); + return runInShellSuccess({"cp", {filePath.path(), target.path()}, OsType::OsTypeLinux}); } bool UnixDeviceFileAccess::renameFile(const FilePath &filePath, const FilePath &target) const { - return runInShellSuccess({"mv", {filePath.path(), target.path()}}); + return runInShellSuccess({"mv", {filePath.path(), target.path()}, OsType::OsTypeLinux}); } FilePath UnixDeviceFileAccess::symLinkTarget(const FilePath &filePath) const { - const RunResult result = runInShell({"readlink", {"-n", "-e", filePath.path()}}); + const RunResult result = runInShell({"readlink", {"-n", "-e", filePath.path()}, OsType::OsTypeLinux}); const QString out = QString::fromUtf8(result.stdOut); return out.isEmpty() ? FilePath() : filePath.withNewPath(out); } @@ -746,7 +746,7 @@ std::optional UnixDeviceFileAccess::fileContents( args += QString("seek=%1").arg(offset / gcd); } - const RunResult r = runInShell({"dd", args}); + const RunResult r = runInShell({"dd", args, OsType::OsTypeLinux}); if (r.exitCode != 0) return {}; @@ -764,7 +764,7 @@ bool UnixDeviceFileAccess::writeFileContents( args.append("bs=1"); args.append(QString("seek=%1").arg(offset)); } - return runInShellSuccess({"dd", args}, data); + return runInShellSuccess({"dd", args, OsType::OsTypeLinux}, data); } OsType UnixDeviceFileAccess::osType(const FilePath &filePath) const @@ -775,7 +775,7 @@ OsType UnixDeviceFileAccess::osType(const FilePath &filePath) const QDateTime UnixDeviceFileAccess::lastModified(const FilePath &filePath) const { - const RunResult result = runInShell({"stat", {"-L", "-c", "%Y", filePath.path()}}); + const RunResult result = runInShell({"stat", {"-L", "-c", "%Y", filePath.path()}, OsType::OsTypeLinux}); qint64 secs = result.stdOut.toLongLong(); const QDateTime dt = QDateTime::fromSecsSinceEpoch(secs, Qt::UTC); return dt; @@ -783,7 +783,7 @@ QDateTime UnixDeviceFileAccess::lastModified(const FilePath &filePath) const QFile::Permissions UnixDeviceFileAccess::permissions(const FilePath &filePath) const { - const RunResult result = runInShell({"stat", {"-L", "-c", "%a", filePath.path()}}); + const RunResult result = runInShell({"stat", {"-L", "-c", "%a", filePath.path()}, OsType::OsTypeLinux}); const uint bits = result.stdOut.toUInt(nullptr, 8); QFileDevice::Permissions perm = {}; #define BIT(n, p) if (bits & (1<