OpenEnroth 73e68f7
|
#include <FileSystem.h>
Public Member Functions | |
FileSystem ()=default | |
virtual | ~FileSystem ()=default |
bool | exists (std::string_view path) const |
bool | exists (FileSystemPathView path) const |
FileStat | stat (std::string_view path) const |
FileStat | stat (FileSystemPathView path) const |
std::vector< DirectoryEntry > | ls (std::string_view path) const |
std::vector< DirectoryEntry > | ls (FileSystemPathView path) const |
void | ls (std::string_view path, std::vector< DirectoryEntry > *entries) const |
void | ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const |
Blob | read (std::string_view path) const |
Blob | read (FileSystemPathView path) const |
void | write (std::string_view path, const Blob &data) |
void | write (FileSystemPathView path, const Blob &data) |
std::unique_ptr< InputStream > | openForReading (std::string_view path) const |
std::unique_ptr< InputStream > | openForReading (FileSystemPathView path) const |
std::unique_ptr< OutputStream > | openForWriting (std::string_view path) |
std::unique_ptr< OutputStream > | openForWriting (FileSystemPathView path) |
void | rename (std::string_view srcPath, std::string_view dstPath) |
void | rename (FileSystemPathView srcPath, FileSystemPathView dstPath) |
bool | remove (std::string_view path) |
bool | remove (FileSystemPathView path) |
std::string | displayPath (std::string_view path) const |
std::string | displayPath (FileSystemPathView path) const |
Protected Types | |
template<class T > | |
using | FileSystemTrieNode = detail::FileSystemTrieNode< T > |
template<class T > | |
using | FileSystemTrie = detail::FileSystemTrie< T > |
Protected Member Functions | |
virtual bool | _exists (FileSystemPathView path) const =0 |
virtual FileStat | _stat (FileSystemPathView path) const =0 |
virtual void | _ls (FileSystemPathView path, std::vector< DirectoryEntry > *entries) const =0 |
virtual Blob | _read (FileSystemPathView path) const =0 |
virtual void | _write (FileSystemPathView path, const Blob &data)=0 |
virtual std::unique_ptr< InputStream > | _openForReading (FileSystemPathView path) const =0 |
virtual std::unique_ptr< OutputStream > | _openForWriting (FileSystemPathView path)=0 |
virtual void | _rename (FileSystemPathView srcPath, FileSystemPathView dstPath) |
virtual bool | _remove (FileSystemPathView path)=0 |
virtual std::string | _displayPath (FileSystemPathView path) const =0 |
Friends | |
class | ProxyFileSystem |
File system interface.
All user-facing methods take paths as UTF8-encoded std::string_view
s, and users are expected to just use std::string
s to store paths.
Paths are normalized internally, and then processed by the implementation in a derived class. Both ".."
and "."
special dirs are supported, but peeking outside the root directory is not - passing paths that try to do this will throw, exists
will return false
, and stat
will return FILE_INVALID
.
Unlike a real file system, this interface doesn't have a concept of a "current directory." All methods take root-relative paths, so "foo/bar"
and "/foo/bar"
are equivalent.
Root folder of the file system always exists. Thus, exists("")
always returns true
, stat("")
always returns FILE_DIRECTORY
, ls("")
never throws, remove("")
and rename("", "foo")
always throw.
|
protected |
|
protected |
|
default |
|
virtualdefault |
|
protectedpure virtual |
|
protectedpure virtual |
|
protectedpure virtual |
|
protectedpure virtual |
|
protectedpure virtual |
Implemented in DirectoryFileSystem, ReadOnlyFileSystem, LowercaseFileSystem, MaskingFileSystem, MemoryFileSystem, MountingFileSystem, and ProxyFileSystem.
|
protectedpure virtual |
|
protectedpure virtual |
Implemented in DirectoryFileSystem, ReadOnlyFileSystem, LowercaseFileSystem, MaskingFileSystem, MemoryFileSystem, MountingFileSystem, and ProxyFileSystem.
|
protectedvirtual |
Reimplemented in DirectoryFileSystem, ReadOnlyFileSystem, LowercaseFileSystem, MaskingFileSystem, MemoryFileSystem, MountingFileSystem, and ProxyFileSystem.
|
protectedpure virtual |
|
protectedpure virtual |
Implemented in DirectoryFileSystem, ReadOnlyFileSystem, LowercaseFileSystem, MaskingFileSystem, MemoryFileSystem, MountingFileSystem, and ProxyFileSystem.
std::string FileSystem::displayPath | ( | FileSystemPathView | path | ) | const |
std::string FileSystem::displayPath | ( | std::string_view | path | ) | const |
path | Path inside this file system. The passed path is not required to exist. |
bool FileSystem::exists | ( | FileSystemPathView | path | ) | const |
bool FileSystem::exists | ( | std::string_view | path | ) | const |
path | Path to check. |
std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
std::vector< DirectoryEntry > FileSystem::ls | ( | FileSystemPathView | path | ) | const |
void FileSystem::ls | ( | FileSystemPathView | path, |
std::vector< DirectoryEntry > * | entries | ||
) | const |
std::vector< DirectoryEntry > FileSystem::ls | ( | std::string_view | path | ) | const |
path | Path to an existing directory to list. |
std::runtime_error | If path doesn't exist, or on any other error. |
void FileSystem::ls | ( | std::string_view | path, |
std::vector< DirectoryEntry > * | entries | ||
) | const |
std::unique_ptr< InputStream > FileSystem::openForReading | ( | FileSystemPathView | path | ) | const |
std::unique_ptr< InputStream > FileSystem::openForReading | ( | std::string_view | path | ) | const |
path | Path to an existing file to open for reading. |
std::runtime_error | If path doesn't exist, or on any other error. |
std::unique_ptr< OutputStream > FileSystem::openForWriting | ( | FileSystemPathView | path | ) |
std::unique_ptr< OutputStream > FileSystem::openForWriting | ( | std::string_view | path | ) |
path | Path to a file to write. If parent directory doesn't exist, it will be created. If a file with the provided name exists, it will be overwritten. |
std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
Blob FileSystem::read | ( | FileSystemPathView | path | ) | const |
Blob FileSystem::read | ( | std::string_view | path | ) | const |
path | Path to an existing file to read or map into memory. |
std::runtime_error | If path doesn't exist, or on any other error. |
bool FileSystem::remove | ( | FileSystemPathView | path | ) |
bool FileSystem::remove | ( | std::string_view | path | ) |
path | Path to a file or a directory to remove. A directory will be removed even if it is not empty. Must not be root. |
true
if the file or folder was deleted, false
if it did not exist. std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
void FileSystem::rename | ( | FileSystemPathView | srcPath, |
FileSystemPathView | dstPath | ||
) |
void FileSystem::rename | ( | std::string_view | srcPath, |
std::string_view | dstPath | ||
) |
Renames a file or a folder.
Default implementation removes dstPath
first, then copies the srcPath
over, then removes srcPath
.
Derived classes working on top of an actual file system might implement this using POSIX rename
.
srcPath | Source path for renaming. Path must exist and must not be root. |
dstPath | Target path for renaming. If source path is a directory, then target path must not exist. If source path is a file, then target path must either not exist, or be a file. If parent directory of dstPath doesn't exist, it will be created. |
std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
FileStat FileSystem::stat | ( | FileSystemPathView | path | ) | const |
FileStat FileSystem::stat | ( | std::string_view | path | ) | const |
path | Path to a file of a folder to get information for. |
path
. FileStat::type
will be set to FILE_INVALID
if path
doesn't exist. std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
void FileSystem::write | ( | FileSystemPathView | path, |
const Blob & | data | ||
) |
void FileSystem::write | ( | std::string_view | path, |
const Blob & | data | ||
) |
path | Path to a file to write. If parent directory doesn't exist, it will be created. If a file with the provided name exists, it will be overwritten. |
data | File contents to write. |
std::runtime_error | On error, e.g. if the current user doesn't have the necessary permissions. |
|
friend |