blob: 0c2133dc99656b5cb42d66285f1de2eee9cc9940 [file] [log] [blame]
Alexei Strots1bf05be2023-04-21 11:07:37 -07001#ifndef AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_
2#define AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_
3
4#include <filesystem>
5#include <string>
6#include <vector>
7
8namespace aos::logger::internal {
9
10// Predicate to include or exclude file to be considered as a log file.
11bool IsValidFilename(std::string_view filename);
12
13// Abstraction that supports listing of the logs on file system and S3. It is
14// associated with either a single file or directory that contains log files.
15class FileOperations {
16 public:
Austin Schuh95460cc2023-06-26 11:53:10 -070017 struct File {
18 std::string name;
Andrew Schneer4ca56282024-02-14 17:59:51 -080019 size_t size; // bytes.
Austin Schuh95460cc2023-06-26 11:53:10 -070020 };
21
Alexei Strots1bf05be2023-04-21 11:07:37 -070022 virtual ~FileOperations() = default;
23
24 virtual bool Exists() = 0;
Austin Schuh95460cc2023-06-26 11:53:10 -070025 virtual void FindLogs(std::vector<File> *files) = 0;
Alexei Strots1bf05be2023-04-21 11:07:37 -070026};
27
28// Implements FileOperations with standard POSIX filesystem APIs. These work on
29// files local to the machine they're running on.
30class LocalFileOperations final : public FileOperations {
31 public:
32 explicit LocalFileOperations(std::string_view filename)
33 : filename_(filename) {}
34
35 bool Exists() override { return std::filesystem::exists(filename_); }
36
Austin Schuh95460cc2023-06-26 11:53:10 -070037 void FindLogs(std::vector<File> *files) override;
Alexei Strots1bf05be2023-04-21 11:07:37 -070038
39 private:
40 std::string filename_;
41};
42
43} // namespace aos::logger::internal
44
45#endif // AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_