userver: userver/fs/blocking/read.hpp Source File
Loading...
Searching...
No Matches
read.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/fs/blocking/read.hpp
4/// @brief functions for synchronous (blocking) file read operations
5/// @ingroup userver_universal
6
7#include <string>
8
9#include <userver/fs/file_info_with_data.hpp>
10#include <userver/fs/settings_read_file.hpp>
11#include <userver/utils/boost_filesystem_file_status.hpp>
12#include <userver/utils/zstring_view.hpp>
13
14USERVER_NAMESPACE_BEGIN
15
16/// @brief blocking function and classes to work with filesystem
17///
18/// Use these with caution as they block current thread. It is probably OK to
19/// use them during startup (on component load), but don't use them after server
20/// start in the main TaskProcessor. Use asynchronous alternatives from `fs`
21/// namespace instead.
22namespace fs::blocking {
23
24/// @brief Reads file contents synchronously
25/// @param path file to open
26/// @returns file contents
27/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
28/// read error, etc.),
30
31/// @brief Checks whether the file exists synchronously
32/// @param path file path to check
33/// @returns true if file exists, false if file doesn't exist
34/// @throws std::runtime_error if something goes wrong (e.g. out of file
35/// descriptors)
36bool FileExists(const std::string& path);
37
38/// @brief Get file type returned by stat(2) synchronously.
39/// @param path file path
40/// @throws std::runtime_error if something goes wrong
41boost::filesystem::file_type GetFileType(const std::string& path);
42
43/// @brief Returns files from recursively traversed directory
44/// @param path to directory to traverse recursively
45/// @param flags settings read files
46/// @returns map with relative to `path` filepaths and file info
47/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
48/// read error, etc.),
49FileInfoWithDataMap ReadRecursiveFilesInfoWithData(const std::string& path, SettingReadFileFlags flags);
50
51} // namespace fs::blocking
52
53USERVER_NAMESPACE_END