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
13USERVER_NAMESPACE_BEGIN
14
15/// @brief blocking function and classes to work with filesystem
16///
17/// Use these with caution as they block current thread. It is probably OK to
18/// use them during startup (on component load), but don't use them after server
19/// start in the main TaskProcessor. Use asynchronous alternatives from `fs`
20/// namespace instead.
21namespace fs::blocking {
22
23/// @brief Reads file contents synchronously
24/// @param path file to open
25/// @returns file contents
26/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
27/// read error, etc.),
28std::string ReadFileContents(const std::string& path);
29
30/// @brief Checks whether the file exists synchronously
31/// @param path file path to check
32/// @returns true if file exists, false if file doesn't exist
33/// @throws std::runtime_error if something goes wrong (e.g. out of file
34/// descriptors)
35bool FileExists(const std::string& path);
36
37/// @brief Get file type returned by stat(2) synchronously.
38/// @param path file path
39/// @throws std::runtime_error if something goes wrong
40boost::filesystem::file_type GetFileType(const std::string& path);
41
42/// @brief Returns files from recursively traversed directory
43/// @param path to directory to traverse recursively
44/// @param flags settings read files
45/// @returns map with relative to `path` filepaths and file info
46/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
47/// read error, etc.),
48FileInfoWithDataMap ReadRecursiveFilesInfoWithData(const std::string& path, SettingReadFileFlags flags);
49
50} // namespace fs::blocking
51
52USERVER_NAMESPACE_END