blob: faf63cbb43ac805af2e3054849ee4e7646d0846c [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:
17 virtual ~FileOperations() = default;
18
19 virtual bool Exists() = 0;
20 virtual void FindLogs(std::vector<std::string> *files) = 0;
21};
22
23// Implements FileOperations with standard POSIX filesystem APIs. These work on
24// files local to the machine they're running on.
25class LocalFileOperations final : public FileOperations {
26 public:
27 explicit LocalFileOperations(std::string_view filename)
28 : filename_(filename) {}
29
30 bool Exists() override { return std::filesystem::exists(filename_); }
31
32 void FindLogs(std::vector<std::string> *files) override;
33
34 private:
35 std::string filename_;
36};
37
38} // namespace aos::logger::internal
39
40#endif // AOS_EVENTS_LOGGING_FILE_OPERATIONS_H_