diff options
author | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-01-12 13:08:23 +0100 |
---|---|---|
committer | Marcus Tillmanns <marcus.tillmanns@qt.io> | 2023-01-20 13:31:51 +0000 |
commit | 2d491591e2e7b757ffa5cfcb597eb34960885042 (patch) | |
tree | c6e613682fe1fe75d0f78125e6cc79763dd0e092 | |
parent | e9320a812252b05a6367462fea698d35f9585eae (diff) | |
download | qt-creator-2d491591e2e7b757ffa5cfcb597eb34960885042.tar.gz |
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 <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
-rw-r--r-- | src/libs/utils/filepath.cpp | 6 | ||||
-rw-r--r-- | src/libs/utils/filepath.h | 1 | ||||
-rw-r--r-- | src/libs/utils/fsengine/fsengine.cpp | 3 |
3 files changed, 9 insertions, 1 deletions
diff --git a/src/libs/utils/filepath.cpp b/src/libs/utils/filepath.cpp index a5b3381acc..f2b3f2a19a 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 d0fb810e46..eb043effe3 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 6a9665f6d0..e715049311 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) |