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 <cstddef>
8#include <limits>
9
10#include <userver/fs/file_info_with_data.hpp>
11#include <userver/fs/settings_read_file.hpp>
12#include <userver/utils/boost_filesystem_file_status.hpp>
13#include <userver/utils/zstring_view.hpp>
14
15USERVER_NAMESPACE_BEGIN
16
17/// @brief blocking function and classes to work with filesystem
18///
19/// Use these with caution as they block current thread. It is probably OK to
20/// use them during startup (on component load), but don't use them after server
21/// start in the main TaskProcessor. Use asynchronous alternatives from `fs`
22/// namespace instead.
23namespace fs::blocking {
24
25/// @brief Reads file contents synchronously
26/// @param path file to open
27/// @returns file contents
28/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
29/// read error, etc.),
31
32/// @brief Checks whether the file exists synchronously
33/// @param path file path to check
34/// @returns true if file exists, false if file doesn't exist
35/// @throws std::runtime_error if something goes wrong (e.g. out of file
36/// descriptors)
38
39/// @brief Get file type returned by stat(2) synchronously.
40/// @param path file path
41/// @throws std::runtime_error if something goes wrong
42boost::filesystem::file_type GetFileType(utils::zstring_view path);
43
44/// @brief Returns files from recursively traversed directory
45/// @param path to directory to traverse recursively
46/// @param flags settings read files
47/// @param max_size_to_cache files larger than this store a full path in
48/// `FileInfoWithData::data_or_path` instead of contents
49/// @returns map with relative to `path` filepaths and file info
50/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
51/// read error, etc.),
53 utils::zstring_view path,
54 SettingReadFileFlags flags,
55 std::size_t max_size_to_cache = std::numeric_limits<std::size_t>::max()
56);
57
58} // namespace fs::blocking
59
60USERVER_NAMESPACE_END