Alexei Strots | 1bf05be | 2023-04-21 11:07:37 -0700 | [diff] [blame] | 1 | #include "aos/events/logging/file_operations.h" |
| 2 | |
| 3 | #include "absl/strings/match.h" |
| 4 | #include "glog/logging.h" |
| 5 | |
| 6 | namespace aos::logger::internal { |
| 7 | |
| 8 | bool IsValidFilename(std::string_view filename) { |
| 9 | return absl::EndsWith(filename, ".bfbs") || |
| 10 | absl::EndsWith(filename, ".bfbs.xz") || |
| 11 | absl::EndsWith(filename, ".bfbs.sz"); |
| 12 | } |
| 13 | |
| 14 | void LocalFileOperations::FindLogs(std::vector<std::string> *files) { |
| 15 | auto MaybeAddFile = [&files](std::string_view filename) { |
| 16 | if (!IsValidFilename(filename)) { |
| 17 | VLOG(1) << "Ignoring " << filename << " with invalid extension."; |
| 18 | } else { |
| 19 | VLOG(1) << "Found log " << filename; |
| 20 | files->emplace_back(filename); |
| 21 | } |
| 22 | }; |
| 23 | if (std::filesystem::is_directory(filename_)) { |
| 24 | VLOG(1) << "Searching in " << filename_; |
| 25 | for (const auto &file : |
| 26 | std::filesystem::recursive_directory_iterator(filename_)) { |
| 27 | if (!file.is_regular_file()) { |
| 28 | VLOG(1) << file << " is not file."; |
| 29 | continue; |
| 30 | } |
| 31 | MaybeAddFile(file.path().string()); |
| 32 | } |
| 33 | } else { |
| 34 | MaybeAddFile(filename_); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } // namespace aos::logger::internal |