Extract s3 file operations to separate file
Preparation for reading from memory. It will be called from log backend.
Change-Id: Ie2b6fff413fae08cc66afccb17d02b99a987847d
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/events/logging/file_operations.cc b/aos/events/logging/file_operations.cc
new file mode 100644
index 0000000..75910e5
--- /dev/null
+++ b/aos/events/logging/file_operations.cc
@@ -0,0 +1,38 @@
+#include "aos/events/logging/file_operations.h"
+
+#include "absl/strings/match.h"
+#include "glog/logging.h"
+
+namespace aos::logger::internal {
+
+bool IsValidFilename(std::string_view filename) {
+ return absl::EndsWith(filename, ".bfbs") ||
+ absl::EndsWith(filename, ".bfbs.xz") ||
+ absl::EndsWith(filename, ".bfbs.sz");
+}
+
+void LocalFileOperations::FindLogs(std::vector<std::string> *files) {
+ auto MaybeAddFile = [&files](std::string_view filename) {
+ if (!IsValidFilename(filename)) {
+ VLOG(1) << "Ignoring " << filename << " with invalid extension.";
+ } else {
+ VLOG(1) << "Found log " << filename;
+ files->emplace_back(filename);
+ }
+ };
+ if (std::filesystem::is_directory(filename_)) {
+ VLOG(1) << "Searching in " << filename_;
+ for (const auto &file :
+ std::filesystem::recursive_directory_iterator(filename_)) {
+ if (!file.is_regular_file()) {
+ VLOG(1) << file << " is not file.";
+ continue;
+ }
+ MaybeAddFile(file.path().string());
+ }
+ } else {
+ MaybeAddFile(filename_);
+ }
+}
+
+} // namespace aos::logger::internal