blob: 75910e5084b048722c710ff245f673e520b31fbf [file] [log] [blame]
Alexei Strots1bf05be2023-04-21 11:07:37 -07001#include "aos/events/logging/file_operations.h"
2
3#include "absl/strings/match.h"
4#include "glog/logging.h"
5
6namespace aos::logger::internal {
7
8bool 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
14void 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