diff options
author | hjk <[email protected]> | 2021-07-01 11:26:59 +0200 |
---|---|---|
committer | hjk <[email protected]> | 2021-07-02 06:29:12 +0000 |
commit | 9287b1a3be7d8fc85036738d0503ec9fd66945c5 (patch) | |
tree | 179cc38c8ea6829869e169cde30f4d5e12a1f9c2 /src/libs/utils/fileutils.cpp | |
parent | 9a35983b0936649d512c289ca6a8d87b898a967c (diff) |
Utils: Introduce FilePath::is{Relative,Absolute}Path
To operate correctly with remote target files systems that do not
match the host OS.
Change-Id: Ia4ea284dc38399deacb50410c9618e1e139f4e13
Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/libs/utils/fileutils.cpp')
-rw-r--r-- | src/libs/utils/fileutils.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/libs/utils/fileutils.cpp b/src/libs/utils/fileutils.cpp index 8ea7cedf584..9e68b91853d 100644 --- a/src/libs/utils/fileutils.cpp +++ b/src/libs/utils/fileutils.cpp @@ -358,22 +358,32 @@ QString FileUtils::normalizePathName(const QString &name) #endif } -bool FileUtils::isRelativePath(const QString &path) +static bool isRelativePathHelper(const QString &path, OsType osType) { - if (path.startsWith(QLatin1Char('/'))) + if (path.startsWith('/')) return false; - if (HostOsInfo::isWindowsHost()) { - if (path.startsWith(QLatin1Char('\\'))) + if (osType == OsType::OsTypeWindows) { + if (path.startsWith('\\')) return false; // Unlike QFileInfo, this won't accept a relative path with a drive letter. // Such paths result in a royal mess anyway ... - if (path.length() >= 3 && path.at(1) == QLatin1Char(':') && path.at(0).isLetter() - && (path.at(2) == QLatin1Char('/') || path.at(2) == QLatin1Char('\\'))) + if (path.length() >= 3 && path.at(1) == ':' && path.at(0).isLetter() + && (path.at(2) == '/' || path.at(2) == '\\')) return false; } return true; } +bool FileUtils::isRelativePath(const QString &path) +{ + return isRelativePathHelper(path, HostOsInfo::hostOs()); +} + +bool FilePath::isRelativePath() const +{ + return isRelativePathHelper(m_data, osType()); +} + FilePath FilePath::resolvePath(const QString &fileName) const { if (fileName.isEmpty()) @@ -1055,7 +1065,7 @@ FilePath FilePath::absoluteFilePath() const FilePath FilePath::absoluteFilePath(const FilePath &tail) const { - if (FileUtils::isRelativePath(tail.m_data)) + if (isRelativePathHelper(tail.m_data, osType())) return pathAppended(tail.m_data); return tail; } |