Utils: improve path correction

Change-Id: I1479bd7e7d2d2cf12eb6858bf92269bd454115a1
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
hjk
2023-08-31 11:25:04 +02:00
parent 67212a31ee
commit ff274be0b2

View File

@@ -10,6 +10,7 @@
#include "fsengine.h" #include "fsengine.h"
#include "../algorithm.h" #include "../algorithm.h"
#include "../hostosinfo.h"
namespace Utils::Internal { namespace Utils::Internal {
@@ -33,6 +34,18 @@ static FilePath removeDoubleSlash(const QString &fileName)
return FilePath::fromString(result); 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 QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
{ {
if (fileName.startsWith(':')) if (fileName.startsWith(':'))
@@ -71,7 +84,7 @@ QAbstractFileEngine *FSEngineHandler::create(const QString &fileName) const
return new FSEngineImpl(removeDoubleSlash(fileName)); return new FSEngineImpl(removeDoubleSlash(fileName));
} }
if (fixedFileName.compare(HostOsInfo::root().path(), Qt::CaseInsensitive) == 0) if (isRootPath(fixedFileName))
return new RootInjectFSEngine(fileName); return new RootInjectFSEngine(fileName);
return nullptr; return nullptr;