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 
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         std::unique_ptr<FileSystemInterface> helper)
32 {
33     return std::make_unique<FileCleanupHandler>(blobId, files,
34                                                 std::move(helper));
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, const std::vector<uint8_t>&)
48 {
49     for (const auto& file : files)
50     {
51         helper->remove(file);
52     }
53 
54     return true;
55 }
56 
57 } // namespace ipmi_flash
58