blob: 5073d4688dc27b3884e218385d04d6dc6adc8d87 [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:
Patrick Williams42a44c22024-08-16 15:21:32 -040017 static std::unique_ptr<blobs::GenericBlobInterface> CreateCleanupHandler(
18 const std::string& blobId, const std::vector<std::string>& files,
19 std::unique_ptr<FileSystemInterface> helper);
Patrick Venture9efef5d2019-06-19 08:45:44 -070020
21 FileCleanupHandler(const std::string& blobId,
22 const std::vector<std::string>& files,
Patrick Venture2950c252020-07-16 15:11:03 -070023 std::unique_ptr<FileSystemInterface> helper) :
Patrick Williams42a44c22024-08-16 15:21:32 -040024 supported(blobId), files(files), helper(std::move(helper))
Patrick Venture9b37b092020-05-28 20:58:57 -070025 {}
Patrick Venture9efef5d2019-06-19 08:45:44 -070026
27 ~FileCleanupHandler() = default;
28 FileCleanupHandler(const FileCleanupHandler&) = default;
29 FileCleanupHandler& operator=(const FileCleanupHandler&) = default;
30 FileCleanupHandler(FileCleanupHandler&&) = default;
31 FileCleanupHandler& operator=(FileCleanupHandler&&) = default;
32
33 bool canHandleBlob(const std::string& path) override;
34 std::vector<std::string> getBlobIds() override;
35 bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
36
37 /* These methods return true without doing anything. */
Willy Tub487eb42021-09-16 21:44:43 -070038 bool open(uint16_t, uint16_t, const std::string&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070039 {
40 return true;
41 }
Willy Tub487eb42021-09-16 21:44:43 -070042 bool close(uint16_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070043 {
44 return true;
45 }
Willy Tub487eb42021-09-16 21:44:43 -070046 bool expire(uint16_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070047 {
48 return true;
49 }
50
51 /* These methods are unsupported. */
Willy Tub487eb42021-09-16 21:44:43 -070052 bool deleteBlob(const std::string&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070053 {
54 return false;
55 }
Willy Tub487eb42021-09-16 21:44:43 -070056 bool stat(const std::string&, blobs::BlobMeta*) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070057 {
58 return false;
59 }
Willy Tub487eb42021-09-16 21:44:43 -070060 std::vector<uint8_t> read(uint16_t, uint32_t, uint32_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070061 {
62 return {};
63 }
Willy Tub487eb42021-09-16 21:44:43 -070064 bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070065 {
66 return false;
67 }
Willy Tub487eb42021-09-16 21:44:43 -070068 bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070069 {
70 return false;
71 }
Willy Tub487eb42021-09-16 21:44:43 -070072 bool stat(uint16_t, blobs::BlobMeta*) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070073 {
74 return false;
75 }
76
77 private:
78 std::string supported;
79 std::vector<std::string> files;
Patrick Venture2950c252020-07-16 15:11:03 -070080 std::unique_ptr<FileSystemInterface> helper;
Patrick Venture9efef5d2019-06-19 08:45:44 -070081};
82
83} // namespace ipmi_flash