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> |
Patrick Venture | 9b37b09 | 2020-05-28 20:58:57 -0700 | [diff] [blame] | 20 | |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 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( |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 30 | const std::string& blobId, const std::vector<std::string>& files, |
| 31 | std::unique_ptr<FileSystemInterface> helper) |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 32 | { |
Patrick Venture | 2950c25 | 2020-07-16 15:11:03 -0700 | [diff] [blame] | 33 | return std::make_unique<FileCleanupHandler>(blobId, files, |
| 34 | std::move(helper)); |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | bool FileCleanupHandler::canHandleBlob(const std::string& path) |
| 38 | { |
| 39 | return (path == supported); |
| 40 | } |
| 41 | |
| 42 | std::vector<std::string> FileCleanupHandler::getBlobIds() |
| 43 | { |
| 44 | return {supported}; |
| 45 | } |
| 46 | |
| 47 | bool FileCleanupHandler::commit(uint16_t session, |
| 48 | const std::vector<uint8_t>& data) |
| 49 | { |
Patrick Venture | 9efef5d | 2019-06-19 08:45:44 -0700 | [diff] [blame] | 50 | for (const auto& file : files) |
| 51 | { |
| 52 | helper->remove(file); |
| 53 | } |
| 54 | |
| 55 | return true; |
| 56 | } |
| 57 | |
| 58 | } // namespace ipmi_flash |