vasilvv | 90615e3 | 2021-07-02 08:12:43 -0700 | [diff] [blame] | 1 | #include "common/platform/api/quiche_file_utils.h" |
| 2 | |
| 3 | #include "quiche_platform_impl/quiche_file_utils_impl.h" |
| 4 | |
| 5 | namespace quiche { |
| 6 | |
| 7 | std::string JoinPath(absl::string_view a, absl::string_view b) { |
| 8 | return JoinPathImpl(a, b); |
| 9 | } |
| 10 | |
| 11 | absl::optional<std::string> ReadFileContents(absl::string_view file) { |
| 12 | return ReadFileContentsImpl(file); |
| 13 | } |
| 14 | |
| 15 | bool 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 | |
| 21 | bool 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 | |
| 45 | bool 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 |