diff options
author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-20 00:01:23 -0500 |
---|---|---|
committer | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-09-20 05:27:16 -0500 |
commit | e4693a7f44b7f95d94aecf2aa3c481d7ed1cd3a2 (patch) | |
tree | 8e1576db88188a4b4463bbb3601cda846f99ca81 | |
parent | 2496482acd4df532ebb2850679d2b55680c2ec9f (diff) | |
download | phosphor-debug-collector-e4693a7f44b7f95d94aecf2aa3c481d7ed1cd3a2.tar.gz phosphor-debug-collector-e4693a7f44b7f95d94aecf2aa3c481d7ed1cd3a2.zip |
phosphor-dump-manager: Fix for deserialize cereal exception
This commit provides a fix for an issue in which the cereal
deserialize() would crash the phosphor-dump-manager incase
persistence file is empty in restore path.
Change-Id: I25259acf50f67cbc8d7b7ac3030bd7bfffbdfa47
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
-rw-r--r-- | dump_serialize.cpp | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/dump_serialize.cpp b/dump_serialize.cpp index 26990a0..13a8b7e 100644 --- a/dump_serialize.cpp +++ b/dump_serialize.cpp @@ -2,6 +2,8 @@ #include <cereal/archives/binary.hpp> #include <fstream> +#include <phosphor-logging/log.hpp> + #include "dump_serialize.hpp" namespace phosphor @@ -11,6 +13,8 @@ namespace dump namespace elog { +using namespace phosphor::logging; + void serialize(const ElogList& list, const fs::path& dir) { std::ofstream os(dir.c_str(), std::ios::binary); @@ -20,14 +24,23 @@ void serialize(const ElogList& list, const fs::path& dir) bool deserialize(const fs::path& path, ElogList& list) { - if (fs::exists(path)) + try + { + if (fs::exists(path)) + { + std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); + cereal::BinaryInputArchive iarchive(is); + iarchive(list); + return true; + } + return false; + } + catch(cereal::Exception& e) { - std::ifstream is(path.c_str(), std::ios::in | std::ios::binary); - cereal::BinaryInputArchive iarchive(is); - iarchive(list); - return true; + log<level::ERR>(e.what()); + fs::remove(path); + return false; } - return false; } } // namespace elog |