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.h b/aos/events/logging/file_operations.h
new file mode 100644
index 0000000..faf63cb
--- /dev/null
+++ b/aos/events/logging/file_operations.h
@@ -0,0 +1,40 @@
+#ifndef AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_
+#define AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_
+
+#include <filesystem>
+#include <string>
+#include <vector>
+
+namespace aos::logger::internal {
+
+// Predicate to include or exclude file to be considered as a log file.
+bool IsValidFilename(std::string_view filename);
+
+// Abstraction that supports listing of the logs on file system and S3. It is
+// associated with either a single file or directory that contains log files.
+class FileOperations {
+ public:
+ virtual ~FileOperations() = default;
+
+ virtual bool Exists() = 0;
+ virtual void FindLogs(std::vector<std::string> *files) = 0;
+};
+
+// Implements FileOperations with standard POSIX filesystem APIs. These work on
+// files local to the machine they're running on.
+class LocalFileOperations final : public FileOperations {
+ public:
+ explicit LocalFileOperations(std::string_view filename)
+ : filename_(filename) {}
+
+ bool Exists() override { return std::filesystem::exists(filename_); }
+
+ void FindLogs(std::vector<std::string> *files) override;
+
+ private:
+ std::string filename_;
+};
+
+} // namespace aos::logger::internal
+
+#endif // AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_