diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index 34b7c3d0af1..b71b4e6c752 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -932,9 +932,9 @@ void FilePath::setFromString(const QStringView fileNameView) setParts({}, {}, fileNameView); } -DeviceFileAccess *FilePath::fileAccess() const +expected_str getFileAccess(const FilePath &filePath) { - if (!needsDevice()) + if (!filePath.needsDevice()) return DesktopDeviceFileAccess::instance(); if (!s_deviceHooks.fileAccess) { @@ -943,12 +943,23 @@ DeviceFileAccess *FilePath::fileAccess() const return DesktopDeviceFileAccess::instance(); } + return s_deviceHooks.fileAccess(filePath); +} + +DeviceFileAccess *FilePath::fileAccess() const +{ static DeviceFileAccess dummy; - const expected_str access = s_deviceHooks.fileAccess(*this); + const expected_str access = getFileAccess(*this); QTC_ASSERT_EXPECTED(access, return &dummy); return *access ? *access : &dummy; } +bool FilePath::hasFileAccess() const +{ + const expected_str access = getFileAccess(*this); + return access && access.value(); +} + /*! Constructs a FilePath from \a filePath. The \a defaultExtension is appended to \a filePath if that does not have an extension already. diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index b9af9cc05b8..658aaec8e0a 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -212,6 +212,7 @@ public: // There are usually other means available. E.g. distinguishing based // on FilePath::osType(). bool needsDevice() const; + bool hasFileAccess() const; bool isSameDevice(const FilePath &other) const; bool isSameFile(const FilePath &other) const; diff --git a/src/libs/utils/fsengine/fsengine.cpp b/src/libs/utils/fsengine/fsengine.cpp index 56daca3b457..c97fee7345a 100644 --- a/src/libs/utils/fsengine/fsengine.cpp +++ b/src/libs/utils/fsengine/fsengine.cpp @@ -36,7 +36,7 @@ FilePaths FSEngine::registeredDeviceRoots() void FSEngine::addDevice(const FilePath &deviceRoot) { - if (deviceRoot.exists()) + if (deviceRoot.hasFileAccess()) deviceRoots().append(deviceRoot); } @@ -53,7 +53,7 @@ FilePaths &FSEngine::deviceRoots() QStringList &FSEngine::deviceSchemes() { - static QStringList g_deviceSchemes {"device"}; + static QStringList g_deviceSchemes{"device"}; return g_deviceSchemes; }