bmc: add cleanup blob handler
Add a cleanup blob handler, such that there is a new blob id present
named "/flash/cleanup" that will delete temporary files. This blob
handler expects a client to open/commit/close the blob. This blob
handler will delete files that are specified as temporary. The host
client may use this to clean up artifacts on verification or update
failure.
This can be extended later to handle calling a service or doing anything
else to cleanup. The cleanup handler will be added if
--enable-cleanup-delete. The recipe will automatically add this blob
handler if that configure variable is set.
Tested: Not tested on real hardware.
Signed-off-by: Patrick Venture <venture@google.com>
Change-Id: I4502b2613e38f0a947d7235d084287376c6b0ce1
diff --git a/cleanup/cleanup.hpp b/cleanup/cleanup.hpp
new file mode 100644
index 0000000..7c528af
--- /dev/null
+++ b/cleanup/cleanup.hpp
@@ -0,0 +1,88 @@
+#pragma once
+
+#include "fs.hpp"
+
+#include <blobs-ipmid/blobs.hpp>
+#include <memory>
+#include <string>
+#include <vector>
+
+namespace ipmi_flash
+{
+
+class FileCleanupHandler : public blobs::GenericBlobInterface
+{
+ public:
+ static std::unique_ptr<blobs::GenericBlobInterface>
+ CreateCleanupHandler(const std::string& blobId,
+ const std::vector<std::string>& files);
+
+ FileCleanupHandler(const std::string& blobId,
+ const std::vector<std::string>& files,
+ const FileSystemInterface* helper = &fileSystemHelper) :
+ supported(blobId),
+ files(files), helper(helper)
+ {
+ }
+
+ ~FileCleanupHandler() = default;
+ FileCleanupHandler(const FileCleanupHandler&) = default;
+ FileCleanupHandler& operator=(const FileCleanupHandler&) = default;
+ FileCleanupHandler(FileCleanupHandler&&) = default;
+ FileCleanupHandler& operator=(FileCleanupHandler&&) = default;
+
+ bool canHandleBlob(const std::string& path) override;
+ std::vector<std::string> getBlobIds() override;
+ bool commit(uint16_t session, const std::vector<uint8_t>& data) override;
+
+ /* These methods return true without doing anything. */
+ bool open(uint16_t session, uint16_t flags,
+ const std::string& path) override
+ {
+ return true;
+ }
+ bool close(uint16_t session) override
+ {
+ return true;
+ }
+ bool expire(uint16_t session) override
+ {
+ return true;
+ }
+
+ /* These methods are unsupported. */
+ bool deleteBlob(const std::string& path) override
+ {
+ return false;
+ }
+ bool stat(const std::string& path, blobs::BlobMeta* meta) override
+ {
+ return false;
+ }
+ std::vector<uint8_t> read(uint16_t session, uint32_t offset,
+ uint32_t requestedSize) override
+ {
+ return {};
+ }
+ bool write(uint16_t session, uint32_t offset,
+ const std::vector<uint8_t>& data) override
+ {
+ return false;
+ }
+ bool writeMeta(uint16_t session, uint32_t offset,
+ const std::vector<uint8_t>& data) override
+ {
+ return false;
+ }
+ bool stat(uint16_t session, blobs::BlobMeta* meta) override
+ {
+ return false;
+ }
+
+ private:
+ std::string supported;
+ std::vector<std::string> files;
+ const FileSystemInterface* helper;
+};
+
+} // namespace ipmi_flash