diff options
author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-19 23:53:31 -0500 |
---|---|---|
committer | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-20 01:43:57 -0500 |
commit | e39f379014439fc2f200c083b39a3cbeb8cbb766 (patch) | |
tree | 57d03f105405a4c3e51894810a16bf9d7159636f | |
parent | 033fc3bd74ab101778e0f50e8a81f151b08b176c (diff) | |
download | phosphor-state-manager-e39f379014439fc2f200c083b39a3cbeb8cbb766.tar.gz phosphor-state-manager-e39f379014439fc2f200c083b39a3cbeb8cbb766.zip |
Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-host-state-manager,
incase persistence file is empty in restore path.
Change-Id: I5f7774166b5a719fa035b2a2cd4f041303a1e6bf
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
-rw-r--r-- | host_state_manager.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/host_state_manager.cpp b/host_state_manager.cpp index 0991cf7..ab60030 100644 --- a/host_state_manager.cpp +++ b/host_state_manager.cpp @@ -297,14 +297,23 @@ fs::path Host::serialize(const fs::path& dir) bool Host::deserialize(const fs::path& path) { - if (fs::exists(path)) + try { - std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); - cereal::JSONInputArchive iarchive(is); - iarchive(*this); - return true; + if (fs::exists(path)) + { + std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); + cereal::JSONInputArchive iarchive(is); + iarchive(*this); + return true; + } + return false; + } + catch(cereal::Exception& e) + { + log<level::ERR>(e.what()); + fs::remove(path); + return false; } - return false; } Host::Transition Host::requestedHostTransition(Transition value) |