From 2d491591e2e7b757ffa5cfcb597eb34960885042 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Thu, 12 Jan 2023 13:08:23 +0100 Subject: [PATCH] Utils: Add FilePath.hasFileAccess() FilePath::hasFileAccess allows a user to test if a specific device can access files. This is faster than calling "exists()" as it does not have to actually check anything on the device. cherry picked from commit 21ef25a0f5aa957857528861a960aeb1f2bb9180 Task-number: QTCREATORBUG-28531 Change-Id: I363ca634d921464fe4ec68397c09fba49dccee25 Reviewed-by: Eike Ziller Reviewed-by: --- src/libs/utils/filepath.cpp | 6 ++++++ src/libs/utils/filepath.h | 1 + src/libs/utils/fsengine/fsengine.cpp | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index a5b3381acc6..f2b3f2a19a9 100644 --- a/src/libs/utils/filepath.cpp +++ b/src/libs/utils/filepath.cpp @@ -826,6 +826,12 @@ DeviceFileAccess *FilePath::fileAccess() const return access; } +bool FilePath::hasFileAccess() const +{ + DeviceFileAccess *access = s_deviceHooks.fileAccess(*this); + return access; +} + /// Constructs a FilePath from \a filePath. The \a defaultExtension is appended /// to \a filename if that does not have an extension already. /// \a filePath is not checked for validity. diff --git a/src/libs/utils/filepath.h b/src/libs/utils/filepath.h index d0fb810e465..eb043effe30 100644 --- a/src/libs/utils/filepath.h +++ b/src/libs/utils/filepath.h @@ -207,6 +207,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 6a9665f6d05..e7150493111 100644 --- a/src/libs/utils/fsengine/fsengine.cpp +++ b/src/libs/utils/fsengine/fsengine.cpp @@ -36,7 +36,8 @@ FilePaths FSEngine::registeredDeviceRoots() void FSEngine::addDevice(const FilePath &deviceRoot) { - deviceRoots().append(deviceRoot); + if (deviceRoot.hasFileAccess()) + deviceRoots().append(deviceRoot); } void FSEngine::removeDevice(const FilePath &deviceRoot)