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