blob: fc0c189382efe4fdc4c010f12622d8905c968682 [file] [log] [blame]
vasilvv90615e32021-07-02 08:12:43 -07001#include "common/platform/api/quiche_file_utils.h"
2
3#include "quiche_platform_impl/quiche_file_utils_impl.h"
4
5namespace quiche {
6
7std::string JoinPath(absl::string_view a, absl::string_view b) {
8 return JoinPathImpl(a, b);
9}
10
11absl::optional<std::string> ReadFileContents(absl::string_view file) {
12 return ReadFileContentsImpl(file);
13}
14
15bool EnumerateDirectory(absl::string_view path,
16 std::vector<std::string>& directories,
17 std::vector<std::string>& files) {
18 return EnumerateDirectoryImpl(path, directories, files);
19}
20
21bool EnumerateDirectoryRecursivelyInner(absl::string_view path,
22 int recursion_limit,
23 std::vector<std::string>& files) {
24 if (recursion_limit < 0) {
25 return false;
26 }
27
28 std::vector<std::string> local_files;
29 std::vector<std::string> directories;
30 if (!EnumerateDirectory(path, directories, local_files)) {
31 return false;
32 }
33 for (const std::string& directory : directories) {
34 if (!EnumerateDirectoryRecursivelyInner(JoinPath(path, directory),
35 recursion_limit - 1, files)) {
36 return false;
37 }
38 }
39 for (const std::string& file : local_files) {
40 files.push_back(JoinPath(path, file));
41 }
42 return true;
43}
44
45bool EnumerateDirectoryRecursively(absl::string_view path,
46 std::vector<std::string>& files) {
47 constexpr int kRecursionLimit = 20;
48 return EnumerateDirectoryRecursivelyInner(path, kRecursionLimit, files);
49}
50
51} // namespace quiche