summaryrefslogtreecommitdiffstats
path: root/settings_manager.mako.hpp
diff options
context:
space:
mode:
authorTom Joseph <tomjoseph@in.ibm.com>2017-09-24 20:47:24 +0530
committerBrad Bishop <bradleyb@fuzziesquirrel.com>2017-09-28 19:37:36 +0000
commit4636e07c194b01da42b5bcaa813200077b539ad7 (patch)
tree3711df3552027cf7d1b4e30f047f0fa000a48fea /settings_manager.mako.hpp
parentba39928b501399816ba343ef4ac16ee644ea9bf5 (diff)
downloadphosphor-settingsd-4636e07c194b01da42b5bcaa813200077b539ad7.tar.gz
phosphor-settingsd-4636e07c194b01da42b5bcaa813200077b539ad7.zip
cereal: Fix empty file scenario
Cereal throws execption when deserialising empty file, add code to handle empty exception and default the setting to the default value. Change-Id: I466f44d07c902a27344a483b5b574e0507baa2f4 Signed-off-by: Tom Joseph <tomjoseph@in.ibm.com>
Diffstat (limited to 'settings_manager.mako.hpp')
-rw-r--r--settings_manager.mako.hpp33
1 files changed, 24 insertions, 9 deletions
diff --git a/settings_manager.mako.hpp b/settings_manager.mako.hpp
index 1dbe550..9e0b3fd 100644
--- a/settings_manager.mako.hpp
+++ b/settings_manager.mako.hpp
@@ -43,6 +43,7 @@ def get_setting_type(path):
#include <phosphor-logging/log.hpp>
#include "config.h"
#include <xyz/openbmc_project/Common/error.hpp>
+using namespace phosphor::logging;
% for i in set(sdbusplus_includes):
#include "${i}"
@@ -297,22 +298,36 @@ class Manager
% for index, path in enumerate(objects):
path = fs::path(SETTINGS_PERSIST_PATH) / "${path}";
path += persistent::fileSuffix;
- if (fs::exists(path))
- {
- std::ifstream is(path.c_str(), std::ios::in);
- cereal::JSONInputArchive iarchive(is);
- iarchive(*std::get<${index}>(settings));
- }
- else
+ auto initSetting${index} = [&]()
{
% for item in settingsDict[path]:
% for propName, metaDict in item['Properties'].items():
<% p = propName[:1].lower() + propName[1:] %>\
<% defaultValue = metaDict['Default'] %>\
std::get<${index}>(settings)->
- ${get_setting_sdbusplus_type(item['Interface'])}::${p}(${defaultValue});
- % endfor
+ ${get_setting_sdbusplus_type(item['Interface'])}::${p}(${defaultValue});
% endfor
+% endfor
+ };
+
+ try
+ {
+ if (fs::exists(path))
+ {
+ std::ifstream is(path.c_str(), std::ios::in);
+ cereal::JSONInputArchive iarchive(is);
+ iarchive(*std::get<${index}>(settings));
+ }
+ else
+ {
+ initSetting${index}();
+ }
+ }
+ catch (cereal::Exception& e)
+ {
+ log<level::ERR>(e.what());
+ fs::remove(path);
+ initSetting${index}();
}
std::get<${index}>(settings)->emit_object_added();
OpenPOWER on IntegriCloud