userver: userver/fs/blocking/write.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
write.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/fs/blocking/write.hpp
4/// @brief Functions for synchronous (blocking) file write operations
5/// @ingroup userver_universal
6
7#include <string>
8#include <string_view>
9
10#include <boost/filesystem/operations.hpp>
11
12USERVER_NAMESPACE_BEGIN
13
14namespace fs::blocking {
15
16/// @{
17/// @brief Create directory and all necessary parent elements. Condition when
18/// path already exists and is a directory treated as "success" and no exception
19/// is thrown.
20/// @param path directory to create
21/// @param perms new directory permissions, default=0755
22/// @throws std::runtime_error if an error occurred while creating directories
23void CreateDirectories(std::string_view path, boost::filesystem::perms perms);
24
25void CreateDirectories(std::string_view path);
26/// @}
27
28/// @brief Rewrite file contents synchronously
29/// @param path file to rewrite
30/// @param contents new file contents
31/// @throws std::runtime_error if failed to overwrite
32/// @see fs::RewriteFileContents
33void RewriteFileContents(const std::string& path, std::string_view contents);
34
35/// @brief flushes directory contents on disk using sync(2)
36/// @param path directory to flush
37void SyncDirectoryContents(const std::string& path);
38
39/// @brief Renames existing file synchronously
40/// @param source path to move from
41/// @param destination path to move to
42/// @throws std::runtime_error
43void Rename(const std::string& source, const std::string& destination);
44
45/// @brief Change file mode synchronously
46/// @param path file path to chmod
47/// @param perms new file permissions
48/// @throws std::runtime_error
49void Chmod(const std::string& path, boost::filesystem::perms perms);
50
51/// @brief Remove existing file synchronously
52/// @param path file path to chmod
53/// @returns true if successfully removed, false if file doesn't exist
54/// @throws std::runtime_error
55bool RemoveSingleFile(const std::string& path);
56
57} // namespace fs::blocking
58
59USERVER_NAMESPACE_END