userver: fs Namespace Reference
Loading...
Searching...
No Matches
fs Namespace Reference

Detailed Description

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)
 

Typedef Documentation

◆ FileInfoWithDataConstPtr

using fs::FileInfoWithDataConstPtr = std::shared_ptr<const FileInfoWithData>

Definition at line 24 of file read.hpp.

◆ FileInfoWithDataMap

using fs::FileInfoWithDataMap
Initial value:
std::unordered_map<std::string, FileInfoWithDataConstPtr>

Definition at line 25 of file read.hpp.

Enumeration Type Documentation

◆ SettingsReadFile

enum class fs::SettingsReadFile
strong
Enumerator
kSkipHidden 

Skip hidden files,.

Definition at line 28 of file read.hpp.

Function Documentation

◆ Chmod()

void fs::Chmod ( engine::TaskProcessor & async_tp,
const std::string & path,
boost::filesystem::perms perms )

Change file mode.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile path to chmod
permsnew file permissions
Exceptions
std::runtime_error

◆ CreateDirectories()

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.

Parameters
async_tpTaskProcessor for synchronous waiting
pathdirectory to create
Exceptions
std::runtime_errorif there was an error while creating directories

◆ FileExists()

bool fs::FileExists ( engine::TaskProcessor & async_tp,
const std::string & path )

Checks whether the file exists asynchronosly.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile path to check
Returns
true if file exists, false if file doesn't exist
Exceptions
std::runtime_errorif something goes wrong (e.g. out of file descriptors)

◆ GetLexicallyRelative()

std::string fs::GetLexicallyRelative ( std::string_view path,
std::string_view dir )

Returns relative path from full path.

Parameters
pathfull path, must start with dir
dirdirectory path to get relative path
Note
it does not access filesystem, the relative path is calculated lexically.

◆ ReadFileContents()

std::string fs::ReadFileContents ( engine::TaskProcessor & async_tp,
const std::string & path )

Reads file contents asynchronously.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile to open
Returns
file contents
Exceptions
std::runtime_errorif read fails for any reason (e.g. no such file, read error, etc.),

◆ ReadRecursiveFilesInfoWithData()

FileInfoWithDataMap fs::ReadRecursiveFilesInfoWithData ( engine::TaskProcessor & async_tp,
const std::string & path,
utils::Flags< SettingsReadFile > flags = {SettingsReadFile::kSkipHidden} )

Returns files from recursively traversed directory.

Parameters
async_tpTaskProcessor for synchronous waiting
pathto directory to traverse recursively
flagssettings read files
Returns
map with relative to path filepaths and file info
Exceptions
std::runtime_errorif read fails for any reason (e.g. no such file, read error, etc.),

◆ RemoveSingleFile()

bool fs::RemoveSingleFile ( engine::TaskProcessor & async_tp,
const std::string & path )

Remove existing file.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile path to chmod
Returns
true if successfully removed, false if file doesn't exist
Exceptions
std::runtime_error

◆ Rename()

void fs::Rename ( engine::TaskProcessor & async_tp,
const std::string & source,
const std::string & destination )

Renames existing file.

Parameters
async_tpTaskProcessor for synchronous waiting
sourcepath to move from
destinationpath to move to
Exceptions
std::runtime_error

◆ RewriteFileContents()

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.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile to rewrite
contentsnew file contents
Exceptions
std::runtime_errorif failed to overwrite

◆ RewriteFileContentsAtomically()

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.

Parameters
async_tpTaskProcessor for synchronous waiting
pathfile path to rewrite
contentsnew file contents
permsnew file permissions
Exceptions
std::runtime_error