filesystem support
Namespaces | |
namespace | blocking |
blocking function and classes to work with filesystem | |
Classes | |
struct | FileInfoWithData |
Struct file with load data. More... | |
class | FsCacheClient |
Class client for storing files in memory Usually retrieved from components::FsCache More... | |
class | TempFile |
A unique temporary file. The file is deleted when the TempFile object is destroyed. More... | |
Typedefs | |
using | FileInfoWithDataConstPtr = std::shared_ptr<const FileInfoWithData> |
using | FileInfoWithDataMap |
Enumerations | |
enum class | SettingsReadFile { kNone = 0 , kSkipHidden = 1 << 0 } |
Functions | |
std::string | GetLexicallyRelative (std::string_view path, std::string_view dir) |
Returns relative path from full path. | |
FileInfoWithDataMap | ReadRecursiveFilesInfoWithData (engine::TaskProcessor &async_tp, const std::string &path, utils::Flags< SettingsReadFile > flags={SettingsReadFile::kSkipHidden}) |
Returns files from recursively traversed directory. | |
std::string | ReadFileContents (engine::TaskProcessor &async_tp, const std::string &path) |
Reads file contents asynchronously. | |
bool | FileExists (engine::TaskProcessor &async_tp, const std::string &path) |
Checks whether the file exists asynchronosly. | |
void | RewriteFileContents (engine::TaskProcessor &async_tp, const std::string &path, std::string_view contents) |
Rewrite file contents asynchronously It doesn't provide strict atomic guarantees. If you need them, use fs::RewriteFileContentsAtomically . | |
void | Rename (engine::TaskProcessor &async_tp, const std::string &source, const std::string &destination) |
Renames existing file. | |
void | RewriteFileContentsAtomically (engine::TaskProcessor &async_tp, const std::string &path, std::string_view contents, boost::filesystem::perms perms) |
Rewrite file contents atomically Write contents to temporary file in the same directory, then atomically replaces the destination file with the temporary file. Effectively does write()+sync()+rename()+sync(directory). It does both sync(2) for file and on the directory, so after successful return the file must persist on the filesystem. | |
void | Chmod (engine::TaskProcessor &async_tp, const std::string &path, boost::filesystem::perms perms) |
Change file mode. | |
bool | RemoveSingleFile (engine::TaskProcessor &async_tp, const std::string &path) |
Remove existing file. | |
void | CreateDirectories (engine::TaskProcessor &async_tp, std::string_view path, boost::filesystem::perms perms) |
Create directory and all necessary parent elements. Condition when path already exists and is a directory treated as "success" and no exception is thrown. | |
void | CreateDirectories (engine::TaskProcessor &async_tp, std::string_view path) |
using fs::FileInfoWithDataConstPtr = std::shared_ptr<const FileInfoWithData> |
using fs::FileInfoWithDataMap |
|
strong |
void fs::Chmod | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path, | ||
boost::filesystem::perms | perms ) |
Change file mode.
async_tp | TaskProcessor for synchronous waiting |
path | file path to chmod |
perms | new file permissions |
std::runtime_error |
void fs::CreateDirectories | ( | engine::TaskProcessor & | async_tp, |
std::string_view | path, | ||
boost::filesystem::perms | perms ) |
Create directory and all necessary parent elements. Condition when path already exists and is a directory treated as "success" and no exception is thrown.
async_tp | TaskProcessor for synchronous waiting |
path | directory to create |
std::runtime_error | if there was an error while creating directories |
bool fs::FileExists | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path ) |
Checks whether the file exists asynchronosly.
async_tp | TaskProcessor for synchronous waiting |
path | file path to check |
std::runtime_error | if something goes wrong (e.g. out of file descriptors) |
std::string fs::GetLexicallyRelative | ( | std::string_view | path, |
std::string_view | dir ) |
Returns relative path from full path.
path | full path, must start with dir |
dir | directory path to get relative path |
std::string fs::ReadFileContents | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path ) |
Reads file contents asynchronously.
async_tp | TaskProcessor for synchronous waiting |
path | file to open |
std::runtime_error | if read fails for any reason (e.g. no such file, read error, etc.), |
FileInfoWithDataMap fs::ReadRecursiveFilesInfoWithData | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path, | ||
utils::Flags< SettingsReadFile > | flags = {SettingsReadFile::kSkipHidden} ) |
Returns files from recursively traversed directory.
async_tp | TaskProcessor for synchronous waiting |
path | to directory to traverse recursively |
flags | settings read files |
path
filepaths and file info std::runtime_error | if read fails for any reason (e.g. no such file, read error, etc.), |
bool fs::RemoveSingleFile | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path ) |
Remove existing file.
async_tp | TaskProcessor for synchronous waiting |
path | file path to chmod |
std::runtime_error |
void fs::Rename | ( | engine::TaskProcessor & | async_tp, |
const std::string & | source, | ||
const std::string & | destination ) |
Renames existing file.
async_tp | TaskProcessor for synchronous waiting |
source | path to move from |
destination | path to move to |
std::runtime_error |
void fs::RewriteFileContents | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path, | ||
std::string_view | contents ) |
Rewrite file contents asynchronously It doesn't provide strict atomic guarantees. If you need them, use fs::RewriteFileContentsAtomically
.
async_tp | TaskProcessor for synchronous waiting |
path | file to rewrite |
contents | new file contents |
std::runtime_error | if failed to overwrite |
void fs::RewriteFileContentsAtomically | ( | engine::TaskProcessor & | async_tp, |
const std::string & | path, | ||
std::string_view | contents, | ||
boost::filesystem::perms | perms ) |
Rewrite file contents atomically Write contents to temporary file in the same directory, then atomically replaces the destination file with the temporary file. Effectively does write()+sync()+rename()+sync(directory). It does both sync(2) for file and on the directory, so after successful return the file must persist on the filesystem.
async_tp | TaskProcessor for synchronous waiting |
path | file path to rewrite |
contents | new file contents |
perms | new file permissions |
std::runtime_error |