blocking function and classes to work with filesystem More...
Classes | |
class | CFile |
A std::FILE* wrapper. More... | |
class | FileDescriptor |
A file descriptor wrapper. More... | |
class | TempDirectory |
A unique directory for temporary files. The directory is deleted when the TempDirectory is destroyed. More... | |
class | TempFile |
A unique temporary file. The file is deleted when the TempFile object is destroyed. More... | |
Typedefs | |
using | OpenMode = utils::Flags< OpenFlag > |
A set of OpenFlags. | |
Enumerations | |
enum class | OpenFlag { kNone = 0 , kRead = 1 << 0 , kWrite = 1 << 1 , kCreateIfNotExists = 1 << 2 , kExclusiveCreate = 1 << 3 , kTruncate = 1 << 4 , kAppend = 1 << 5 } |
Functions | |
std::string | ReadFileContents (const std::string &path) |
Reads file contents synchronously. | |
bool | FileExists (const std::string &path) |
Checks whether the file exists synchronously. | |
boost::filesystem::file_type | GetFileType (const std::string &path) |
Get file type returned by stat(2) synchronously. | |
void | RewriteFileContents (const std::string &path, std::string_view contents) |
Rewrite file contents synchronously. | |
void | SyncDirectoryContents (const std::string &path) |
flushes directory contents on disk using sync(2) | |
void | Rename (const std::string &source, const std::string &destination) |
Renames existing file synchronously. | |
void | Chmod (const std::string &path, boost::filesystem::perms perms) |
Change file mode synchronously. | |
bool | RemoveSingleFile (const std::string &path) |
Remove existing file synchronously. | |
void | CreateDirectories (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 (std::string_view path) |
blocking function and classes to work with filesystem
Use these with caution as they block current thread. It is probably OK to use them during startup (on component load), but don't use them after server start in the main TaskProcessor. Use asynchronous alternatives from fs
namespace instead.
using fs::blocking::OpenMode = typedef utils::Flags<OpenFlag> |
A set of OpenFlags.
Definition at line 43 of file open_mode.hpp.
|
strong |
Definition at line 13 of file open_mode.hpp.
void fs::blocking::Chmod | ( | const std::string & | path, |
boost::filesystem::perms | perms | ||
) |
Change file mode synchronously.
path | file path to chmod |
perms | new file permissions |
std::runtime_error |
void fs::blocking::CreateDirectories | ( | 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.
path | directory to create |
perms | new directory permissions, default=0755 |
std::runtime_error | if an error occurred while creating directories |
bool fs::blocking::FileExists | ( | const std::string & | path | ) |
Checks whether the file exists synchronously.
path | file path to check |
std::runtime_error | if something goes wrong (e.g. out of file descriptors) |
boost::filesystem::file_type fs::blocking::GetFileType | ( | const std::string & | path | ) |
Get file type returned by stat(2) synchronously.
path | file path |
std::runtime_error | if something goes wrong |
std::string fs::blocking::ReadFileContents | ( | const std::string & | path | ) |
Reads file contents synchronously.
path | file to open |
std::runtime_error | if read fails for any reason (e.g. no such file, read error, etc.), |
bool fs::blocking::RemoveSingleFile | ( | const std::string & | path | ) |
Remove existing file synchronously.
path | file path to chmod |
std::runtime_error |
void fs::blocking::Rename | ( | const std::string & | source, |
const std::string & | destination | ||
) |
Renames existing file synchronously.
source | path to move from |
destination | path to move to |
std::runtime_error |
void fs::blocking::RewriteFileContents | ( | const std::string & | path, |
std::string_view | contents | ||
) |
Rewrite file contents synchronously.
path | file to rewrite |
contents | new file contents |
std::runtime_error | if failed to overwrite |
void fs::blocking::SyncDirectoryContents | ( | const std::string & | path | ) |
flushes directory contents on disk using sync(2)
path | directory to flush |