Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2019 Google Inc. |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "cleanup.hpp" |
| 18 | |
| 19 | #include <blobs-ipmid/blobs.hpp> |
| 20 | #include <filesystem> |
| 21 | #include <memory> |
| 22 | #include <string> |
| 23 | #include <vector> |
| 24 | |
| 25 | namespace ipmi_flash |
| 26 | { |
| 27 | |
| 28 | std::unique_ptr<blobs::GenericBlobInterface> |
| 29 | FileCleanupHandler::CreateCleanupHandler( |
| 30 | const std::string& blobId, const std::vector<std::string>& files) |
| 31 | { |
| 32 | return std::make_unique<FileCleanupHandler>(blobId, files); |
| 33 | } |
| 34 | |
| 35 | bool FileCleanupHandler::canHandleBlob(const std::string& path) |
| 36 | { |
| 37 | return (path == supported); |
| 38 | } |
| 39 | |
| 40 | std::vector<std::string> FileCleanupHandler::getBlobIds() |
| 41 | { |
| 42 | return {supported}; |
| 43 | } |
| 44 | |
| 45 | bool FileCleanupHandler::commit(uint16_t session, |
| 46 | const std::vector<uint8_t>& data) |
| 47 | { |
| 48 | namespace fs = std::filesystem; |
| 49 | |
| 50 | for (const auto& file : files) |
| 51 | { |
| 52 | helper->remove(file); |
| 53 | } |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | } // namespace ipmi_flash |