1 #pragma once
2 
3 #include "fs.hpp"
4 
5 #include <blobs-ipmid/blobs.hpp>
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace ipmi_flash
12 {
13 
14 class FileCleanupHandler : public blobs::GenericBlobInterface
15 {
16   public:
17     static std::unique_ptr<blobs::GenericBlobInterface>
18         CreateCleanupHandler(const std::string& blobId,
19                              const std::vector<std::string>& files,
20                              std::unique_ptr<FileSystemInterface> helper);
21 
22     FileCleanupHandler(const std::string& blobId,
23                        const std::vector<std::string>& files,
24                        std::unique_ptr<FileSystemInterface> helper) :
25         supported(blobId),
26         files(files), helper(std::move(helper))
27     {}
28 
29     ~FileCleanupHandler() = default;
30     FileCleanupHandler(const FileCleanupHandler&) = default;
31     FileCleanupHandler& operator=(const FileCleanupHandler&) = default;
32     FileCleanupHandler(FileCleanupHandler&&) = default;
33     FileCleanupHandler& operator=(FileCleanupHandler&&) = default;
34 
35     bool canHandleBlob(const std::string& path) override;
36     std::vector<std::string> getBlobIds() override;
37     bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
38 
39     /* These methods return true without doing anything. */
40     bool open(uint16_t, uint16_t, const std::string&) override
41     {
42         return true;
43     }
44     bool close(uint16_t) override
45     {
46         return true;
47     }
48     bool expire(uint16_t) override
49     {
50         return true;
51     }
52 
53     /* These methods are unsupported. */
54     bool deleteBlob(const std::string&) override
55     {
56         return false;
57     }
58     bool stat(const std::string&, blobs::BlobMeta*) override
59     {
60         return false;
61     }
62     std::vector<uint8_t> read(uint16_t, uint32_t, uint32_t) override
63     {
64         return {};
65     }
66     bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override
67     {
68         return false;
69     }
70     bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override
71     {
72         return false;
73     }
74     bool stat(uint16_t, blobs::BlobMeta*) override
75     {
76         return false;
77     }
78 
79   private:
80     std::string supported;
81     std::vector<std::string> files;
82     std::unique_ptr<FileSystemInterface> helper;
83 };
84 
85 } // namespace ipmi_flash
86