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 <christian.stenger@qt.io>
This commit is contained in:
hjk
2022-09-13 10:38:02 +02:00
parent 4119181762
commit b3200b7730
4 changed files with 3 additions and 8 deletions

View File

@@ -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) == ':';
}
/*!

View File

@@ -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:
}

View File

@@ -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) {

View File

@@ -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<FilePath>("path");
QTest::addColumn<bool>("expected");