Skip to content

Commit

Permalink
Add QgsFileUtils::pathIsSlowDevice to determine whether a file path
Browse files Browse the repository at this point in the history
likely resides on a slow device (eg. a remote network location)
  • Loading branch information
nyalldawson committed May 20, 2021
1 parent e3061a8 commit 72a57b2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/core/auto_generated/qgsfileutils.sip.in
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions src/core/qgsfileutils.cpp
Expand Up @@ -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;
}
8 changes: 8 additions & 0 deletions src/core/qgsfileutils.h
Expand Up @@ -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.