OpenAssetIO
An abstract API for generalising interactions between a host application and an asset management system
FileUrlPathConverter Class Reference

Utility class for converting between file system paths and file URLs. More...

#include <path.hpp>

Public Member Functions

 FileUrlPathConverter ()
 Constructor. More...
 
 ~FileUrlPathConverter ()
 Defaulted destructor. More...
 
 FileUrlPathConverter (const FileUrlPathConverter &)=delete
 Explicitly deleted copy constructor. More...
 
 FileUrlPathConverter (FileUrlPathConverter &&) noexcept=delete
 Explicitly deleted move constructor. More...
 
FileUrlPathConverteroperator= (const FileUrlPathConverter &)=delete
 Explicitly deleted copy assignment. More...
 
FileUrlPathConverteroperator= (FileUrlPathConverter &&) noexcept=delete
 Explicitly deleted move assignment. More...
 
Str pathToUrl (std::string_view absolutePath, PathType pathType=PathType::kSystem) const
 Construct a file URL from a path. More...
 
Str pathFromUrl (std::string_view fileUrl, PathType pathType=PathType::kSystem) const
 Construct a path from a file URL. More...
 

Detailed Description

Utility class for converting between file system paths and file URLs.

The PathType argument allows POSIX hosts to process paths/URLs for Windows systems and vice versa.

Construction of this class should not be considered cheap (internally, multiple regex patterns are compiled). Once constructed, an instance can be used to process any number of URLs/paths.

Conversion of Windows UNC paths to file URLs is supported, including \\?\ device paths. However, conversion of file URLs back to Windows paths only supports drive paths or standard UNC share paths, not device paths.

Some corner cases that may be technically valid are not currently supported, and will result in an exception if detected. E.g.

  • Upward traversals (..) as path segments - these may be a security risk.
  • Non-ASCII Windows server names.
  • Windows UNC non-normalised device paths (\\?\) that have forward-slashes within path segments.
  • Percent-encoded path separators.
  • Windows drive letters of the form C|.

Constructor & Destructor Documentation

Constructor.

Defaulted destructor.

Explicitly deleted copy constructor.

FileUrlPathConverter ( FileUrlPathConverter &&  )
deletenoexcept

Explicitly deleted move constructor.

Member Function Documentation

FileUrlPathConverter& operator= ( const FileUrlPathConverter )
delete

Explicitly deleted copy assignment.

FileUrlPathConverter& operator= ( FileUrlPathConverter &&  )
deletenoexcept

Explicitly deleted move assignment.

Str pathFromUrl ( std::string_view  fileUrl,
PathType  pathType = PathType::kSystem 
) const

Construct a path from a file URL.

Note that long Windows paths may exceed the Windows MAX_PATH limit. Working around this, e.g. by transforming the path to a UNC device path (\\?\C:\ or \\?\UNC\host\share), is left up to the caller.

Parameters
fileUrlURL to convert.
pathTypePlatform associated with path.
Returns
Extracted path suitable for the pathType platform.
Exceptions
InputValidationExceptionif the URL or path that it decodes to is invalid or unsupported.
Str pathToUrl ( std::string_view  absolutePath,
PathType  pathType = PathType::kSystem 
) const

Construct a file URL from a path.

The path must be absolute and not contain any upward traversals (..) within it.

Conversion of Windows UNC paths to file URLs is supported, including standard \\ shares, and \\?\ drive and \\?\\UNC\ share device paths.

Note that Windows device paths of the form \\.\ are not supported. This may be added in a future update.

Parameters
absolutePathPath string.
pathTypePlatform associated with path.
Returns
Converted file URL.
Exceptions
InputValidationExceptionif the path is invalid or unsupported.

The documentation for this class was generated from the following file:
  • /src/src/openassetio-core/include/openassetio/utils/path.hpp