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());
}
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

View File

@@ -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);

View File

@@ -5,9 +5,7 @@
#include <QtCore/private/qabstractfileengine_p.h>
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

View File

@@ -39,8 +39,8 @@ namespace ProjectExplorer {
QHash<QString, QIcon> 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 {