blob: 7c528afa5e77bed5a03b2a93d3ee11031505c427 [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>
6#include <memory>
7#include <string>
8#include <vector>
9
10namespace ipmi_flash
11{
12
13class FileCleanupHandler : public blobs::GenericBlobInterface
14{
15 public:
16 static std::unique_ptr<blobs::GenericBlobInterface>
17 CreateCleanupHandler(const std::string& blobId,
18 const std::vector<std::string>& files);
19
20 FileCleanupHandler(const std::string& blobId,
21 const std::vector<std::string>& files,
22 const FileSystemInterface* helper = &fileSystemHelper) :
23 supported(blobId),
24 files(files), helper(helper)
25 {
26 }
27
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