forked from qt-creator/qt-creator
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. Task-number: QTCREATORBUG-28531 Change-Id: I94b5b9e0ae020b81f126c61fd06bb25f3d4a88cb Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -932,9 +932,9 @@ void FilePath::setFromString(const QStringView fileNameView)
|
||||
setParts({}, {}, fileNameView);
|
||||
}
|
||||
|
||||
DeviceFileAccess *FilePath::fileAccess() const
|
||||
expected_str<DeviceFileAccess *> 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<DeviceFileAccess *> access = s_deviceHooks.fileAccess(*this);
|
||||
const expected_str<DeviceFileAccess *> access = getFileAccess(*this);
|
||||
QTC_ASSERT_EXPECTED(access, return &dummy);
|
||||
return *access ? *access : &dummy;
|
||||
}
|
||||
|
||||
bool FilePath::hasFileAccess() const
|
||||
{
|
||||
const expected_str<DeviceFileAccess *> 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.
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user