userver: userver/fs/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/read.hpp
4/// @brief functions for asynchronous file read operations
5
6#include <memory>
7#include <string>
8#include <unordered_map>
9
10#include <userver/engine/task/task_processor_fwd.hpp>
11#include <userver/utils/flags.hpp>
12
13USERVER_NAMESPACE_BEGIN
14
15/// @brief filesystem support
16namespace fs {
17
18/// @brief Struct file with load data
20 std::string data;
21 std::string extension;
22};
23
24using FileInfoWithDataConstPtr = std::shared_ptr<const FileInfoWithData>;
25using FileInfoWithDataMap =
26 std::unordered_map<std::string, FileInfoWithDataConstPtr>;
27
28enum class SettingsReadFile {
29 kNone = 0,
30 /// Skip hidden files,
31 kSkipHidden = 1 << 0,
32};
33
34/// @brief Returns relative path from full path
35/// @param path full path, must start with `dir`
36/// @param dir directory path to get relative path
37/// @note it does not access filesystem, the relative path is calculated
38/// lexically.
39std::string GetLexicallyRelative(std::string_view path, std::string_view dir);
40
41/// @brief Returns files from recursively traversed directory
42/// @param async_tp TaskProcessor for synchronous waiting
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.),
51
52/// @brief Reads file contents asynchronously
53/// @param async_tp TaskProcessor for synchronous waiting
54/// @param path file to open
55/// @returns file contents
56/// @throws std::runtime_error if read fails for any reason (e.g. no such file,
57/// read error, etc.),
58std::string ReadFileContents(engine::TaskProcessor& async_tp,
59 const std::string& path);
60
61/// @brief Checks whether the file exists asynchronosly
62/// @param async_tp TaskProcessor for synchronous waiting
63/// @param path file path to check
64/// @returns true if file exists, false if file doesn't exist
65/// @throws std::runtime_error if something goes wrong (e.g. out of file
66/// descriptors)
67bool FileExists(engine::TaskProcessor& async_tp, const std::string& path);
68
69} // namespace fs
70
71USERVER_NAMESPACE_END