Skip to content
Permalink
Browse files
Add QgsFileUtils::pathIsSlowDevice to determine whether a file path
likely resides on a slow device (eg. a remote network location)
  • Loading branch information
nyalldawson committed May 20, 2021
1 parent e3061a8 commit 72a57b271f233a7a0df96079c1a2cbbaca1b7225
Showing with 41 additions and 0 deletions.
  1. +8 −0 python/core/auto_generated/qgsfileutils.sip.in
  2. +25 −0 src/core/qgsfileutils.cpp
  3. +8 −0 src/core/qgsfileutils.h
@@ -135,6 +135,14 @@ Returns the drive type for the given ``path``.

:raises :: py:class:`QgsNotSupportedException` if determining the drive type is not supported on the current platform.

.. versionadded:: 3.20
%End

static bool pathIsSlowDevice( const QString &path );
%Docstring
Returns ``True`` if the specified ``path`` is known to reside on a slow device, e.g. a remote
network drive or other non-fixed device.

.. versionadded:: 3.20
%End

@@ -335,3 +335,28 @@ QgsFileUtils::DriveType QgsFileUtils::driveType( const QString &path )
#endif
}

bool QgsFileUtils::pathIsSlowDevice( const QString &path )
{
try
{
const DriveType type = driveType( path );
switch ( type )
{
case QgsFileUtils::Unknown:
case QgsFileUtils::Invalid:
case QgsFileUtils::Fixed:
case QgsFileUtils::RamDisk:
return false;

case QgsFileUtils::Removable:
case QgsFileUtils::Remote:
case QgsFileUtils::CdRom:
return true;
}
}
catch ( QgsNotSupportedException & )
{

}
return false;
}
@@ -143,6 +143,14 @@ class CORE_EXPORT QgsFileUtils
*/
static DriveType driveType( const QString &path ) SIP_THROW( QgsNotSupportedException );

/**
* Returns TRUE if the specified \a path is known to reside on a slow device, e.g. a remote
* network drive or other non-fixed device.
*
* \since QGIS 3.20
*/
static bool pathIsSlowDevice( const QString &path );

};

#endif // QGSFILEUTILS_H

0 comments on commit 72a57b2

Please sign in to comment.