From ff274be0b2bd4307489aab9bf7738936edf22a1f Mon Sep 17 00:00:00 2001 From: hjk Date: Thu, 31 Aug 2023 11:25:04 +0200 Subject: [PATCH] Utils: improve path correction Change-Id: I1479bd7e7d2d2cf12eb6858bf92269bd454115a1 Reviewed-by: Marcus Tillmanns --- src/libs/utils/fsengine/fsenginehandler.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/fsengine/fsenginehandler.cpp b/src/libs/utils/fsengine/fsenginehandler.cpp index 55174bc75cd..2f828537d19 100644 --- a/src/libs/utils/fsengine/fsenginehandler.cpp +++ b/src/libs/utils/fsengine/fsenginehandler.cpp @@ -10,6 +10,7 @@ #include "fsengine.h" #include "../algorithm.h" +#include "../hostosinfo.h" namespace Utils::Internal { @@ -33,6 +34,18 @@ static FilePath removeDoubleSlash(const QString &fileName) return FilePath::fromString(result); } +static bool isRootPath(const QString &fileName) +{ + if (HostOsInfo::isWindowsHost()) { + static const QChar lowerDriveLetter = HostOsInfo::root().path().front().toUpper(); + static const QChar upperDriveLetter = HostOsInfo::root().path().front().toLower(); + return fileName.size() == 3 && fileName[1] == ':' && fileName[2] == '/' + && (fileName[0] == lowerDriveLetter || fileName[0] == upperDriveLetter); + } + + return fileName.size() == 1 && fileName[0] == '/'; +} + QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const { if (fileName.startsWith(':')) @@ -71,7 +84,7 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const return new FSEngineImpl(removeDoubleSlash(fileName)); } - if (fixedFileName.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) + if (isRootPath(fixedFileName)) return new RootInjectFSEngine(fileName); return nullptr;