buffet: Fix loading Buffet state when config file is not present When there is no config file for Buffet, it fails to load the device state as well because BuffetConfig::Load() would have not be called at all. Check for existance of the config file before trying to load it. And if it exists, make sure we load it correctly by using CHECK(). Afterwards call BuffetConfig::Load() unconditionally which will load default values if the store is empty. BUG=None TEST=`FEATURES=test emerge-link buffet` Change-Id: Idfb21504fda018bedd228488dc0ad168f64a796a Reviewed-on: https://chromium-review.googlesource.com/271818 Trybot-Ready: Alex Vakulenko <avakulenko@chromium.org> Tested-by: Alex Vakulenko <avakulenko@chromium.org> Reviewed-by: Vitaly Buka <vitalybuka@chromium.org> Commit-Queue: Vitaly Buka <vitalybuka@chromium.org>
diff --git a/buffet/buffet_config.cc b/buffet/buffet_config.cc index a8a753f..0322b08 100644 --- a/buffet/buffet_config.cc +++ b/buffet/buffet_config.cc
@@ -4,6 +4,7 @@ #include "buffet/buffet_config.h" +#include <base/files/file_util.h> #include <base/logging.h> #include <base/strings/string_number_conversions.h> @@ -84,9 +85,11 @@ void BuffetConfig::Load(const base::FilePath& config_path) { chromeos::KeyValueStore store; - if (store.Load(config_path)) { - Load(store); + if (base::PathExists(config_path)) { + CHECK(store.Load(config_path)) << "Unable to read or parse config file at" + << config_path.value(); } + Load(store); } void BuffetConfig::Load(const chromeos::KeyValueStore& store) {