#include "version.hpp" #include "item_updater.hpp" #include #include #include #include #include #include #include #include #include namespace phosphor { namespace software { namespace updater { using namespace sdbusplus::xyz::openbmc_project::Common::Error; using namespace phosphor::logging; using Argument = xyz::openbmc_project::Common::InvalidArgument; std::map Version::getValues( const std::string& filePath, const std::vector& keys) { if (filePath.empty()) { lg2::error("Error filePath is empty"); elog(Argument::ARGUMENT_NAME("FilePath"), Argument::ARGUMENT_VALUE(filePath.c_str())); } std::ifstream efile(filePath); std::string line; std::map ret; while (getline(efile, line)) { if (!line.empty() && line.back() == '\r') { // Remove \r from the end of line line.pop_back(); } for (const auto& key : keys) { auto value = key + "="; auto keySize = value.length(); if (line.compare(0, keySize, value) == 0) { ret.emplace(key, line.substr(keySize)); break; } } } return ret; } std::string Version::getValue(const std::string& filePath, const std::string& key) { std::string ret; auto values = Version::getValues(filePath, {key}); const auto it = values.find(key); if (it != values.end()) { ret = it->second; } return ret; } std::map Version::getExtVersionInfo(const std::string& extVersion) { // The extVersion shall be key/value pairs separated by comma, // e.g. key1=value1,key2=value2 std::map result; std::stringstream ss(extVersion); while (ss.good()) { std::string substr; getline(ss, substr, ','); auto pos = substr.find('='); if (pos != std::string::npos) { std::string key = substr.substr(0, pos); std::string value = substr.substr(pos + 1); result.emplace(key, value); } } return result; } void Delete::delete_() { if (version.eraseCallback) { version.eraseCallback(version.getVersionId()); } } } // namespace updater } // namespace software } // namespace phosphor