blob: 5f87ca5f243af617201d0031b7f86180af1a86a1 [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
Stephan Pleines5ecc8f12024-05-31 20:35:21 -07004#include <stddef.h>
5
Alexei Strots1bf05be2023-04-21 11:07:37 -07006#include <filesystem>
7#include <string>
Stephan Pleines5ecc8f12024-05-31 20:35:21 -07008#include <string_view>
Alexei Strots1bf05be2023-04-21 11:07:37 -07009#include <vector>
10
11namespace aos::logger::internal {
12
13// Predicate to include or exclude file to be considered as a log file.
14bool IsValidFilename(std::string_view filename);
15
16// Abstraction that supports listing of the logs on file system and S3. It is
17// associated with either a single file or directory that contains log files.
18class FileOperations {
19 public:
Austin Schuh95460cc2023-06-26 11:53:10 -070020 struct File {
21 std::string name;
Andrew Schneer4ca56282024-02-14 17:59:51 -080022 size_t size; // bytes.
Austin Schuh95460cc2023-06-26 11:53:10 -070023 };
24
Alexei Strots1bf05be2023-04-21 11:07:37 -070025 virtual ~FileOperations() = default;
26
27 virtual bool Exists() = 0;
Austin Schuh95460cc2023-06-26 11:53:10 -070028 virtual void FindLogs(std::vector<File> *files) = 0;
Alexei Strots1bf05be2023-04-21 11:07:37 -070029};
30
31// Implements FileOperations with standard POSIX filesystem APIs. These work on
32// files local to the machine they're running on.
33class LocalFileOperations final : public FileOperations {
34 public:
35 explicit LocalFileOperations(std::string_view filename)
36 : filename_(filename) {}
37
38 bool Exists() override { return std::filesystem::exists(filename_); }
39
Austin Schuh95460cc2023-06-26 11:53:10 -070040 void FindLogs(std::vector<File> *files) override;
Alexei Strots1bf05be2023-04-21 11:07:37 -070041
42 private:
43 std::string filename_;
44};
45
46} // namespace aos::logger::internal
47
48#endif // AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_