Utils: Fix FilePath::isRootPath()

Change-Id: I287bae74469ba501ecb03d51f04f7aaa5f4a7268
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-08-10 06:44:12 +02:00
parent 4605bf57dd
commit 324e924178
2 changed files with 61 additions and 6 deletions

View File

@@ -204,7 +204,27 @@ FilePath FilePath::currentWorkingPath()
bool FilePath::isRootPath() const
{
// FIXME: Make host-independent
if (needsDevice()) {
QStringView path = pathView();
if (osType() != OsTypeWindows)
return path == QLatin1String("/");
// Remote windows paths look like this: "/c:/", so we remove the leading '/'
if (path.startsWith('/'))
path = path.mid(1);
if (path.length() > 3)
return false;
if (!startsWithDriveLetter())
return false;
if (path.length() == 3 && path[2] != QLatin1Char('/'))
return false;
return true;
}
return *this == FilePath::fromString(QDir::rootPath());
}
@@ -1346,15 +1366,15 @@ bool FilePath::contains(const QString &s) const
/*!
\brief Checks whether the FilePath starts with a drive letter.
Defaults to \c false if it is a non-Windows host or represents a path on device
Returns whether FilePath starts with a drive letter
*/
bool FilePath::startsWithDriveLetter() const
{
const QStringView p = pathView();
return !needsDevice() && p.size() >= 2 && isWindowsDriveLetter(p[0]) && p.at(1) == ':';
QStringView p = pathView();
if (needsDevice() && !p.isEmpty())
p = p.mid(1);
return p.size() >= 2 && isWindowsDriveLetter(p[0]) && p.at(1) == ':';
}
/*!