blob: 6ee8405224bc36521c917794c26a6721cc3ef6a9 [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,
Patrick Venture2950c252020-07-16 15:11:03 -070019 const std::vector<std::string>& files,
20 std::unique_ptr<FileSystemInterface> helper);
Patrick Venture9efef5d2019-06-19 08:45:44 -070021
22 FileCleanupHandler(const std::string& blobId,
23 const std::vector<std::string>& files,
Patrick Venture2950c252020-07-16 15:11:03 -070024 std::unique_ptr<FileSystemInterface> helper) :
Patrick Venture9efef5d2019-06-19 08:45:44 -070025 supported(blobId),
Patrick Venture2950c252020-07-16 15:11:03 -070026 files(files), helper(std::move(helper))
Patrick Venture9b37b092020-05-28 20:58:57 -070027 {}
Patrick Venture9efef5d2019-06-19 08:45:44 -070028
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 session, uint16_t flags,
41 const std::string& path) override
42 {
43 return true;
44 }
45 bool close(uint16_t session) override
46 {
47 return true;
48 }
49 bool expire(uint16_t session) override
50 {
51 return true;
52 }
53
54 /* These methods are unsupported. */
55 bool deleteBlob(const std::string& path) override
56 {
57 return false;
58 }
59 bool stat(const std::string& path, blobs::BlobMeta* meta) override
60 {
61 return false;
62 }
63 std::vector<uint8_t> read(uint16_t session, uint32_t offset,
64 uint32_t requestedSize) override
65 {
66 return {};
67 }
68 bool write(uint16_t session, uint32_t offset,
69 const std::vector<uint8_t>& data) override
70 {
71 return false;
72 }
73 bool writeMeta(uint16_t session, uint32_t offset,
74 const std::vector<uint8_t>& data) override
75 {
76 return false;
77 }
78 bool stat(uint16_t session, blobs::BlobMeta* meta) override
79 {
80 return false;
81 }
82
83 private:
84 std::string supported;
85 std::vector<std::string> files;
Patrick Venture2950c252020-07-16 15:11:03 -070086 std::unique_ptr<FileSystemInterface> helper;
Patrick Venture9efef5d2019-06-19 08:45:44 -070087};
88
89} // namespace ipmi_flash