blob: 3120a3cf30df848ac96caa3c2721a44cb14b04ca [file] [log] [blame]
Patrick Venture9efef5d2019-06-19 08:45:44 -07001#pragma once
2
3#include "fs.hpp"
4
5#include <blobs-ipmid/blobs.hpp>
Patrick Venture9b37b092020-05-28 20:58:57 -07006
Patrick Venture9efef5d2019-06-19 08:45:44 -07007#include <memory>
8#include <string>
9#include <vector>
10
11namespace ipmi_flash
12{
13
14class 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
21 FileCleanupHandler(const std::string& blobId,
22 const std::vector<std::string>& files,
23 const FileSystemInterface* helper = &fileSystemHelper) :
24 supported(blobId),
25 files(files), helper(helper)
Patrick Venture9b37b092020-05-28 20:58:57 -070026 {}
Patrick Venture9efef5d2019-06-19 08:45:44 -070027
28 ~FileCleanupHandler() = default;
29 FileCleanupHandler(const FileCleanupHandler&) = default;
30 FileCleanupHandler& operator=(const FileCleanupHandler&) = default;
31 FileCleanupHandler(FileCleanupHandler&&) = default;
32 FileCleanupHandler& operator=(FileCleanupHandler&&) = default;
33
34 bool canHandleBlob(const std::string& path) override;
35 std::vector<std::string> getBlobIds() override;
36 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
37
38 /* These methods return true without doing anything. */
39 bool open(uint16_t session, uint16_t flags,
40 const std::string& path) override
41 {
42 return true;
43 }
44 bool close(uint16_t session) override
45 {
46 return true;
47 }
48 bool expire(uint16_t session) override
49 {
50 return true;
51 }
52
53 /* These methods are unsupported. */
54 bool deleteBlob(const std::string& path) override
55 {
56 return false;
57 }
58 bool stat(const std::string& path, blobs::BlobMeta* meta) override
59 {
60 return false;
61 }
62 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
63 uint32_t requestedSize) override
64 {
65 return {};
66 }
67 bool write(uint16_t session, uint32_t offset,
68 const std::vector<uint8_t>& data) override
69 {
70 return false;
71 }
72 bool writeMeta(uint16_t session, uint32_t offset,
73 const std::vector<uint8_t>& data) override
74 {
75 return false;
76 }
77 bool stat(uint16_t session, blobs::BlobMeta* meta) override
78 {
79 return false;
80 }
81
82 private:
83 std::string supported;
84 std::vector<std::string> files;
85 const FileSystemInterface* helper;
86};
87
88} // namespace ipmi_flash