From b3200b7730b6ef28f33cb613ac08590894cdd42b Mon Sep 17 00:00:00 2001 From: hjk Date: Tue, 13 Sep 2022 10:38:02 +0200 Subject: [PATCH] Utils: Move 'isWindowsHost' test to startsWithDriveLetter callers "Fixes" one Q_SKIP and makes the implementation OS-agnostic. FilePath::osType() actually depends on the host system for not fully qualified file paths, and that doesn't seem to be the right thing to do in all cases. The caller may actually have more context to decide whether this is needed (e.g. in pathchooser.cpp in the context of "return value from a GUI element, i.e. 'host' implied). Change-Id: Iff80c17094d2deec79d34d0527223fbcf8294935 Reviewed-by: Christian Stenger --- src/libs/utils/filepath.cpp | 4 +--- src/plugins/docker/dockerdevice.cpp | 2 +- src/plugins/projectexplorer/buildaspects.cpp | 2 +- tests/auto/utils/fileutils/tst_fileutils.cpp | 3 --- 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 8948004d6f4..21be6ec9020 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -1001,9 +1001,7 @@ bool FilePath::endsWith(const QString &s) const */ bool FilePath::startsWithDriveLetter() const { - if (needsDevice() || !HostOsInfo::isWindowsHost()) - return false; - return m_path.size() >= 2 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':'; + return !needsDevice() && m_path.size() >= 2 && isWindowsDriveLetter(m_path[0]) && m_path.at(1) == ':'; } /*! diff --git a/src/plugins/docker/dockerdevice.cpp b/src/plugins/docker/dockerdevice.cpp index 68d0ee8866d..c442a6593e3 100644 --- a/src/plugins/docker/dockerdevice.cpp +++ b/src/plugins/docker/dockerdevice.cpp @@ -636,7 +636,7 @@ QString DockerDevice::mapToDevicePath(const Utils::FilePath &globalPath) const // C:/dev/src -> /c/dev/src const FilePath normalized = FilePath::fromString(globalPath.path()).normalizedPathName(); QString path = normalized.path(); - if (normalized.startsWithDriveLetter()) { + if (HostOsInfo::isWindowsHost() && normalized.startsWithDriveLetter()) { const QChar lowerDriveLetter = path.at(0).toLower(); path = '/' + lowerDriveLetter + path.mid(2); // strip C: } diff --git a/src/plugins/projectexplorer/buildaspects.cpp b/src/plugins/projectexplorer/buildaspects.cpp index bf6564614fb..5f80e50eabb 100644 --- a/src/plugins/projectexplorer/buildaspects.cpp +++ b/src/plugins/projectexplorer/buildaspects.cpp @@ -113,7 +113,7 @@ void BuildDirectoryAspect::addToLayout(LayoutBuilder &builder) FilePath BuildDirectoryAspect::fixupDir(const FilePath &dir) { - if (!dir.startsWithDriveLetter()) + if (HostOsInfo::isWindowsHost() && !dir.startsWithDriveLetter()) return {}; const QString dirString = dir.toString().toLower(); const QStringList drives = Utils::transform(QDir::drives(), [](const QFileInfo &fi) { diff --git a/tests/auto/utils/fileutils/tst_fileutils.cpp b/tests/auto/utils/fileutils/tst_fileutils.cpp index 1fa834a7017..ef375913fcd 100644 --- a/tests/auto/utils/fileutils/tst_fileutils.cpp +++ b/tests/auto/utils/fileutils/tst_fileutils.cpp @@ -789,9 +789,6 @@ void tst_fileutils::asyncLocalCopy() void tst_fileutils::startsWithDriveLetter_data() { - if (!HostOsInfo::isWindowsHost()) - QSKIP("This test is only relevant on Windows"); - QTest::addColumn("path"); QTest::addColumn("expected");