#include #include #include #include #include #include #include "version.hpp" #include #include "xyz/openbmc_project/Common/error.hpp" #include "item_updater.hpp" namespace openpower { namespace software { namespace updater { using namespace sdbusplus::xyz::openbmc_project::Common::Error; using namespace phosphor::logging; std::string Version::getId(const std::string& version) { std::stringstream hexId; if (version.empty()) { log("Error version is empty"); elog(xyz::openbmc_project::Common::InvalidArgument:: ARGUMENT_NAME("Version"), xyz::openbmc_project::Common::InvalidArgument:: ARGUMENT_VALUE(version.c_str())); } // Only want 8 hex digits. hexId << std::hex << ((std::hash {}( version)) & 0xFFFFFFFF); return hexId.str(); } std::map Version::getValue( const std::string& filePath, std::map keys) { if (filePath.empty()) { log("Error filePath is empty"); elog(xyz::openbmc_project::Common::InvalidArgument:: ARGUMENT_NAME("FilePath"), xyz::openbmc_project::Common::InvalidArgument:: ARGUMENT_VALUE(filePath.c_str())); } std::ifstream efile; std::string line; efile.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit); try { efile.open(filePath); while (getline(efile, line)) { for(auto& key : keys) { auto value = key.first + "="; auto keySize = value.length(); if (line.compare(0, keySize, value) == 0) { key.second = line.substr(keySize); break; } } } efile.close(); } catch (const std::exception& e) { if (!efile.eof()) { log("Error in reading file"); } efile.close(); } return keys; } void Version::delete_() { parent.erase(getId(version())); } } // namespace updater } // namespace software } // namespace openpower