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 "fs.hpp" 18 19 #include <filesystem> 20 #include <regex> 21 #include <string> 22 #include <vector> 23 24 namespace ipmi_flash 25 { 26 namespace fs = std::filesystem; 27 28 std::vector<std::string> GetJsonList(const std::string& directory) 29 { 30 std::vector<std::string> output; 31 32 for (const auto& p : fs::recursive_directory_iterator(directory)) 33 { 34 auto ps = p.path().string(); 35 36 /** TODO: openbmc/phosphor-ipmi-blobs/blob/de8a16e2e8/fs.cpp#L27 is 37 * nicer, may be worth finding a way to make this into a util. 38 */ 39 if (std::regex_match(ps, std::regex(".+.json$"))) 40 { 41 output.push_back(ps); 42 } 43 } 44 45 return output; 46 } 47 48 } // namespace ipmi_flash 49