1 #include "version.hpp" 2 3 #include "item_updater.hpp" 4 5 #include <fstream> 6 #include <iostream> 7 #include <phosphor-logging/elog-errors.hpp> 8 #include <phosphor-logging/log.hpp> 9 #include <sstream> 10 #include <stdexcept> 11 #include <string> 12 #include <xyz/openbmc_project/Common/error.hpp> 13 14 namespace phosphor 15 { 16 namespace software 17 { 18 namespace updater 19 { 20 21 using namespace sdbusplus::xyz::openbmc_project::Common::Error; 22 using namespace phosphor::logging; 23 using Argument = xyz::openbmc_project::Common::InvalidArgument; 24 25 std::map<std::string, std::string> 26 Version::getValue(const std::string& filePath, 27 std::map<std::string, std::string> keys) 28 { 29 if (filePath.empty()) 30 { 31 log<level::ERR>("Error filePath is empty"); 32 elog<InvalidArgument>(Argument::ARGUMENT_NAME("FilePath"), 33 Argument::ARGUMENT_VALUE(filePath.c_str())); 34 } 35 36 std::ifstream efile; 37 std::string line; 38 efile.exceptions(std::ifstream::failbit | std::ifstream::badbit | 39 std::ifstream::eofbit); 40 41 try 42 { 43 efile.open(filePath); 44 while (getline(efile, line)) 45 { 46 for (auto& key : keys) 47 { 48 auto value = key.first + "="; 49 auto keySize = value.length(); 50 if (line.compare(0, keySize, value) == 0) 51 { 52 key.second = line.substr(keySize); 53 break; 54 } 55 } 56 } 57 efile.close(); 58 } 59 catch (const std::exception& e) 60 { 61 if (!efile.eof()) 62 { 63 log<level::ERR>("Error in reading file"); 64 } 65 efile.close(); 66 } 67 68 return keys; 69 } 70 71 void Delete::delete_() 72 { 73 if (version.eraseCallback) 74 { 75 version.eraseCallback(version.getVersionId()); 76 } 77 } 78 79 } // namespace updater 80 } // namespace software 81 } // namespace phosphor 82