blob: 04e2d94b8a79f72cbf0dbdcb7223ec99952ec18d [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. */
Willy Tub487eb42021-09-16 21:44:43 -070040 bool open(uint16_t, uint16_t, const std::string&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070041 {
42 return true;
43 }
Willy Tub487eb42021-09-16 21:44:43 -070044 bool close(uint16_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070045 {
46 return true;
47 }
Willy Tub487eb42021-09-16 21:44:43 -070048 bool expire(uint16_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070049 {
50 return true;
51 }
52
53 /* These methods are unsupported. */
Willy Tub487eb42021-09-16 21:44:43 -070054 bool deleteBlob(const std::string&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070055 {
56 return false;
57 }
Willy Tub487eb42021-09-16 21:44:43 -070058 bool stat(const std::string&, blobs::BlobMeta*) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070059 {
60 return false;
61 }
Willy Tub487eb42021-09-16 21:44:43 -070062 std::vector<uint8_t> read(uint16_t, uint32_t, uint32_t) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070063 {
64 return {};
65 }
Willy Tub487eb42021-09-16 21:44:43 -070066 bool write(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070067 {
68 return false;
69 }
Willy Tub487eb42021-09-16 21:44:43 -070070 bool writeMeta(uint16_t, uint32_t, const std::vector<uint8_t>&) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070071 {
72 return false;
73 }
Willy Tub487eb42021-09-16 21:44:43 -070074 bool stat(uint16_t, blobs::BlobMeta*) override
Patrick Venture9efef5d2019-06-19 08:45:44 -070075 {
76 return false;
77 }
78
79 private:
80 std::string supported;
81 std::vector<std::string> files;
Patrick Venture2950c252020-07-16 15:11:03 -070082 std::unique_ptr<FileSystemInterface> helper;
Patrick Venture9efef5d2019-06-19 08:45:44 -070083};
84
85} // namespace ipmi_flash