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 21ef25a0f5

Task-number: QTCREATORBUG-28531
Change-Id: I363ca634d921464fe4ec68397c09fba49dccee25
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Marcus Tillmanns
2023-01-12 13:08:23 +01:00
parent e9320a8122
commit 2d491591e2
3 changed files with 9 additions and 1 deletions

View File

@@ -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.

View File

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

View File

@@ -36,6 +36,7 @@ FilePaths FSEngine::registeredDeviceRoots()
void FSEngine::addDevice(const FilePath &deviceRoot)
{
if (deviceRoot.hasFileAccess())
deviceRoots().append(deviceRoot);
}