diff options
author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-19 22:18:45 -0500 |
---|---|---|
committer | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-19 23:58:15 -0500 |
commit | 86ad3c67615c6bad065dc3a2a55d703daf8163e0 (patch) | |
tree | b6a29212a5ccc9c1c630ae61a18c573b326357be | |
parent | 0b6ca10033b4656661778742b48d06d7c2d7c990 (diff) | |
download | phosphor-inventory-manager-86ad3c67615c6bad065dc3a2a55d703daf8163e0.tar.gz phosphor-inventory-manager-86ad3c67615c6bad065dc3a2a55d703daf8163e0.zip |
phosphor-inventory: Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-inventory, incase
persistence file is empty in restore path.
Change-Id: Id1d40a0e401af8acea92775d1f3337c8a897a7ec
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
-rw-r--r-- | serialize.hpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/serialize.hpp b/serialize.hpp index 7c30b9c..7d0b10e 100644 --- a/serialize.hpp +++ b/serialize.hpp @@ -5,6 +5,8 @@ #include <fstream> #include "config.h" +#include <phosphor-logging/log.hpp> + namespace cereal { @@ -12,6 +14,7 @@ namespace fs = std::experimental::filesystem; using Path = std::string; using Interface = std::string; +using namespace phosphor::logging; /** @brief Serialize inventory item * @@ -44,11 +47,19 @@ inline void deserialize( fs::path p(PIM_PERSIST_PATH); p /= path; p /= iface; - if (fs::exists(p)) + try + { + if (fs::exists(p)) + { + std::ifstream is(p, std::ios::in | std::ios::binary); + cereal::JSONInputArchive iarchive(is); + iarchive(object); + } + } + catch(cereal::Exception& e) { - std::ifstream is(p, std::ios::in | std::ios::binary); - cereal::JSONInputArchive iarchive(is); - iarchive(object); + log<level::ERR>(e.what()); + fs::remove(p); } } |