From 06334e1816bd8eaed6289949689e544bf8efb044 Mon Sep 17 00:00:00 2001 From: hjk Date: Fri, 16 Sep 2022 11:14:59 +0200 Subject: [PATCH] Utils: Replace FilePath::rootPath() by some isRootPath() Keeps more context to make it host-independent later. Change-Id: I0f8ad3e8794daa6324662847203200ae378d34b4 Reviewed-by: Christian Stenger Reviewed-by: --- src/libs/utils/filepath.cpp | 5 +++-- src/libs/utils/filepath.h | 6 ++++-- src/libs/utils/fsengine/fsenginehandler.h | 8 ++------ src/plugins/projectexplorer/projectnodes.cpp | 6 +++--- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 8ac85247304..a196f2e3cbf 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -167,9 +167,10 @@ FilePath FilePath::currentWorkingPath() return FilePath::fromString(QDir::currentPath()); } -FilePath FilePath::rootPath() +bool FilePath::isRootPath() const { - return FilePath::fromString(QDir::rootPath()); + // FIXME: Make host-independent + return operator==(FilePath::fromString(QDir::rootPath())); } QString FilePath::encodedHost() const diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index c71201426ca..981505e84ab 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -59,11 +59,9 @@ public: [[nodiscard]] static FilePath fromParts(const QStringView scheme, const QStringView host, const QStringView path); [[nodiscard]] static FilePath currentWorkingPath(); - [[nodiscard]] static FilePath rootPath(); QString toUserOutput() const; QString toString() const; - QString toFSPathString() const; QVariant toVariant() const; QUrl toUrl() const; @@ -102,6 +100,7 @@ public: bool isAbsolutePath() const { return !isRelativePath(); } bool isFile() const; bool isDir() const; + bool isRootPath() const; bool isNewerThan(const QDateTime &timeStamp) const; QDateTime lastModified() const; QFile::Permissions permissions() const; @@ -191,6 +190,7 @@ public: [[nodiscard]] QFileInfo toFileInfo() const; [[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info); + // Support for FSEngine. Do not use unless needed. enum class SpecialPathComponent { RootName, RootPath, @@ -201,6 +201,8 @@ public: [[nodiscard]] static QString specialPath(SpecialPathComponent component); [[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component); + QString toFSPathString() const; + private: friend class ::tst_fileutils; static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); diff --git a/src/libs/utils/fsengine/fsenginehandler.h b/src/libs/utils/fsengine/fsenginehandler.h index ca179ddd040..66453cd3527 100644 --- a/src/libs/utils/fsengine/fsenginehandler.h +++ b/src/libs/utils/fsengine/fsenginehandler.h @@ -5,9 +5,7 @@ #include -namespace Utils { - -namespace Internal { +namespace Utils::Internal { class FSEngineHandler : public QAbstractFileEngineHandler { @@ -15,6 +13,4 @@ public: QAbstractFileEngine *create(const QString &fileName) const override; }; -} // namespace Internal - -} // namespace Utils +} // Utils::Internal diff --git a/src/plugins/projectexplorer/projectnodes.cpp b/src/plugins/projectexplorer/projectnodes.cpp index bf9fffc57d8..ab02a6ee9e1 100644 --- a/src/plugins/projectexplorer/projectnodes.cpp +++ b/src/plugins/projectexplorer/projectnodes.cpp @@ -39,8 +39,8 @@ namespace ProjectExplorer { QHash DirectoryIcon::m_cache; static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder, - const Utils::FilePath &directory, - const Utils::FilePath &overrideBaseDir, + const FilePath &directory, + const FilePath &overrideBaseDir, const FolderNode::FolderNodeFactory &factory) { Utils::FilePath path = overrideBaseDir.isEmpty() ? folder->filePath() : overrideBaseDir; @@ -48,7 +48,7 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder, Utils::FilePath directoryWithoutPrefix; bool isRelative = false; - if (path.isEmpty() || path == FilePath::rootPath()) { + if (path.isEmpty() || path.isRootPath()) { directoryWithoutPrefix = directory; isRelative = false; } else {