Utils: Replace FilePath::rootPath() by some isRootPath()

Keeps more context to make it host-independent later.

Change-Id: I0f8ad3e8794daa6324662847203200ae378d34b4
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-09-16 11:14:59 +02:00
parent eda8a4244f
commit 06334e1816
4 changed files with 12 additions and 13 deletions

View File

@@ -167,9 +167,10 @@ FilePath FilePath::currentWorkingPath()
return FilePath::fromString(QDir::currentPath()); 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 QString FilePath::encodedHost() const

View File

@@ -59,11 +59,9 @@ public:
[[nodiscard]] static FilePath fromParts(const QStringView scheme, const QStringView host, const QStringView path); [[nodiscard]] static FilePath fromParts(const QStringView scheme, const QStringView host, const QStringView path);
[[nodiscard]] static FilePath currentWorkingPath(); [[nodiscard]] static FilePath currentWorkingPath();
[[nodiscard]] static FilePath rootPath();
QString toUserOutput() const; QString toUserOutput() const;
QString toString() const; QString toString() const;
QString toFSPathString() const;
QVariant toVariant() const; QVariant toVariant() const;
QUrl toUrl() const; QUrl toUrl() const;
@@ -102,6 +100,7 @@ public:
bool isAbsolutePath() const { return !isRelativePath(); } bool isAbsolutePath() const { return !isRelativePath(); }
bool isFile() const; bool isFile() const;
bool isDir() const; bool isDir() const;
bool isRootPath() const;
bool isNewerThan(const QDateTime &timeStamp) const; bool isNewerThan(const QDateTime &timeStamp) const;
QDateTime lastModified() const; QDateTime lastModified() const;
QFile::Permissions permissions() const; QFile::Permissions permissions() const;
@@ -191,6 +190,7 @@ public:
[[nodiscard]] QFileInfo toFileInfo() const; [[nodiscard]] QFileInfo toFileInfo() const;
[[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info); [[nodiscard]] static FilePath fromFileInfo(const QFileInfo &info);
// Support for FSEngine. Do not use unless needed.
enum class SpecialPathComponent { enum class SpecialPathComponent {
RootName, RootName,
RootPath, RootPath,
@@ -201,6 +201,8 @@ public:
[[nodiscard]] static QString specialPath(SpecialPathComponent component); [[nodiscard]] static QString specialPath(SpecialPathComponent component);
[[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component); [[nodiscard]] static FilePath specialFilePath(SpecialPathComponent component);
QString toFSPathString() const;
private: private:
friend class ::tst_fileutils; friend class ::tst_fileutils;
static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath); static QString calcRelativePath(const QString &absolutePath, const QString &absoluteAnchorPath);

View File

@@ -5,9 +5,7 @@
#include <QtCore/private/qabstractfileengine_p.h> #include <QtCore/private/qabstractfileengine_p.h>
namespace Utils { namespace Utils::Internal {
namespace Internal {
class FSEngineHandler : public QAbstractFileEngineHandler class FSEngineHandler : public QAbstractFileEngineHandler
{ {
@@ -15,6 +13,4 @@ public:
QAbstractFileEngine *create(const QString &fileName) const override; QAbstractFileEngine *create(const QString &fileName) const override;
}; };
} // namespace Internal } // Utils::Internal
} // namespace Utils

View File

@@ -39,8 +39,8 @@ namespace ProjectExplorer {
QHash<QString, QIcon> DirectoryIcon::m_cache; QHash<QString, QIcon> DirectoryIcon::m_cache;
static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder, static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
const Utils::FilePath &directory, const FilePath &directory,
const Utils::FilePath &overrideBaseDir, const FilePath &overrideBaseDir,
const FolderNode::FolderNodeFactory &factory) const FolderNode::FolderNodeFactory &factory)
{ {
Utils::FilePath path = overrideBaseDir.isEmpty() ? folder->filePath() : overrideBaseDir; Utils::FilePath path = overrideBaseDir.isEmpty() ? folder->filePath() : overrideBaseDir;
@@ -48,7 +48,7 @@ static FolderNode *recursiveFindOrCreateFolderNode(FolderNode *folder,
Utils::FilePath directoryWithoutPrefix; Utils::FilePath directoryWithoutPrefix;
bool isRelative = false; bool isRelative = false;
if (path.isEmpty() || path == FilePath::rootPath()) { if (path.isEmpty() || path.isRootPath()) {
directoryWithoutPrefix = directory; directoryWithoutPrefix = directory;
isRelative = false; isRelative = false;
} else { } else {