Loading init/apex_init_util.cpp +11 −10 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,6 @@ #include <glob.h> #include <glob.h> #include <map> #include <vector> #include <vector> #include <android-base/logging.h> #include <android-base/logging.h> Loading Loading @@ -66,18 +65,20 @@ static Result<std::vector<std::string>> CollectApexConfigs(const std::string& ap } } static Result<void> ParseConfigs(const std::vector<std::string>& configs) { static Result<void> ParseConfigs(const std::vector<std::string>& configs) { Parser parser = CreateApexConfigParser(ActionManager::GetInstance(), Parser parser = ServiceList::GetInstance()); CreateApexConfigParser(ActionManager::GetInstance(), ServiceList::GetInstance()); bool success = true; std::vector<std::string> errors; for (const auto& c : configs) { for (const auto& c : configs) { success &= parser.ParseConfigFile(c); auto result = parser.ParseConfigFile(c); // We should handle other config files even when there's an error. if (!result.ok()) { errors.push_back(result.error().message()); } } if (success) { return {}; } else { return Error() << "Unable to parse apex configs"; } } if (!errors.empty()) { return Error() << "Unable to parse apex configs: " << base::Join(errors, "|"); } return {}; } } Result<void> ParseApexConfigs(const std::string& apex_name) { Result<void> ParseApexConfigs(const std::string& apex_name) { Loading init/parser.cpp +11 −7 Original line number Original line Diff line number Diff line Loading @@ -141,19 +141,19 @@ bool Parser::ParseConfigFileInsecure(const std::string& path) { return true; return true; } } bool Parser::ParseConfigFile(const std::string& path) { Result<void> Parser::ParseConfigFile(const std::string& path) { LOG(INFO) << "Parsing file " << path << "..."; LOG(INFO) << "Parsing file " << path << "..."; android::base::Timer t; android::base::Timer t; auto config_contents = ReadFile(path); auto config_contents = ReadFile(path); if (!config_contents.ok()) { if (!config_contents.ok()) { LOG(INFO) << "Unable to read config file '" << path << "': " << config_contents.error(); return Error() << "Unable to read config file '" << path return false; << "': " << config_contents.error(); } } ParseData(path, &config_contents.value()); ParseData(path, &config_contents.value()); LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; return true; return {}; } } bool Parser::ParseConfigDir(const std::string& path) { bool Parser::ParseConfigDir(const std::string& path) { Loading @@ -176,8 +176,8 @@ bool Parser::ParseConfigDir(const std::string& path) { // Sort first so we load files in a consistent order (bug 31996208) // Sort first so we load files in a consistent order (bug 31996208) std::sort(files.begin(), files.end()); std::sort(files.begin(), files.end()); for (const auto& file : files) { for (const auto& file : files) { if (!ParseConfigFile(file)) { if (auto result = ParseConfigFile(file); !result.ok()) { LOG(ERROR) << "could not import file '" << file << "'"; LOG(ERROR) << "could not import file '" << file << "': " << result.error(); } } } } return true; return true; Loading @@ -187,7 +187,11 @@ bool Parser::ParseConfig(const std::string& path) { if (is_dir(path.c_str())) { if (is_dir(path.c_str())) { return ParseConfigDir(path); return ParseConfigDir(path); } } return ParseConfigFile(path); auto result = ParseConfigFile(path); if (!result.ok()) { LOG(INFO) << result.error(); } return result.ok(); } } } // namespace init } // namespace init Loading init/parser.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -72,7 +72,7 @@ class Parser { Parser(); Parser(); bool ParseConfig(const std::string& path); bool ParseConfig(const std::string& path); bool ParseConfigFile(const std::string& path); Result<void> ParseConfigFile(const std::string& path); void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); void AddSingleLineParser(const std::string& prefix, LineCallback callback); void AddSingleLineParser(const std::string& prefix, LineCallback callback); Loading Loading
init/apex_init_util.cpp +11 −10 Original line number Original line Diff line number Diff line Loading @@ -18,7 +18,6 @@ #include <glob.h> #include <glob.h> #include <map> #include <vector> #include <vector> #include <android-base/logging.h> #include <android-base/logging.h> Loading Loading @@ -66,18 +65,20 @@ static Result<std::vector<std::string>> CollectApexConfigs(const std::string& ap } } static Result<void> ParseConfigs(const std::vector<std::string>& configs) { static Result<void> ParseConfigs(const std::vector<std::string>& configs) { Parser parser = CreateApexConfigParser(ActionManager::GetInstance(), Parser parser = ServiceList::GetInstance()); CreateApexConfigParser(ActionManager::GetInstance(), ServiceList::GetInstance()); bool success = true; std::vector<std::string> errors; for (const auto& c : configs) { for (const auto& c : configs) { success &= parser.ParseConfigFile(c); auto result = parser.ParseConfigFile(c); // We should handle other config files even when there's an error. if (!result.ok()) { errors.push_back(result.error().message()); } } if (success) { return {}; } else { return Error() << "Unable to parse apex configs"; } } if (!errors.empty()) { return Error() << "Unable to parse apex configs: " << base::Join(errors, "|"); } return {}; } } Result<void> ParseApexConfigs(const std::string& apex_name) { Result<void> ParseApexConfigs(const std::string& apex_name) { Loading
init/parser.cpp +11 −7 Original line number Original line Diff line number Diff line Loading @@ -141,19 +141,19 @@ bool Parser::ParseConfigFileInsecure(const std::string& path) { return true; return true; } } bool Parser::ParseConfigFile(const std::string& path) { Result<void> Parser::ParseConfigFile(const std::string& path) { LOG(INFO) << "Parsing file " << path << "..."; LOG(INFO) << "Parsing file " << path << "..."; android::base::Timer t; android::base::Timer t; auto config_contents = ReadFile(path); auto config_contents = ReadFile(path); if (!config_contents.ok()) { if (!config_contents.ok()) { LOG(INFO) << "Unable to read config file '" << path << "': " << config_contents.error(); return Error() << "Unable to read config file '" << path return false; << "': " << config_contents.error(); } } ParseData(path, &config_contents.value()); ParseData(path, &config_contents.value()); LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; LOG(VERBOSE) << "(Parsing " << path << " took " << t << ".)"; return true; return {}; } } bool Parser::ParseConfigDir(const std::string& path) { bool Parser::ParseConfigDir(const std::string& path) { Loading @@ -176,8 +176,8 @@ bool Parser::ParseConfigDir(const std::string& path) { // Sort first so we load files in a consistent order (bug 31996208) // Sort first so we load files in a consistent order (bug 31996208) std::sort(files.begin(), files.end()); std::sort(files.begin(), files.end()); for (const auto& file : files) { for (const auto& file : files) { if (!ParseConfigFile(file)) { if (auto result = ParseConfigFile(file); !result.ok()) { LOG(ERROR) << "could not import file '" << file << "'"; LOG(ERROR) << "could not import file '" << file << "': " << result.error(); } } } } return true; return true; Loading @@ -187,7 +187,11 @@ bool Parser::ParseConfig(const std::string& path) { if (is_dir(path.c_str())) { if (is_dir(path.c_str())) { return ParseConfigDir(path); return ParseConfigDir(path); } } return ParseConfigFile(path); auto result = ParseConfigFile(path); if (!result.ok()) { LOG(INFO) << result.error(); } return result.ok(); } } } // namespace init } // namespace init Loading
init/parser.h +1 −1 Original line number Original line Diff line number Diff line Loading @@ -72,7 +72,7 @@ class Parser { Parser(); Parser(); bool ParseConfig(const std::string& path); bool ParseConfig(const std::string& path); bool ParseConfigFile(const std::string& path); Result<void> ParseConfigFile(const std::string& path); void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); void AddSectionParser(const std::string& name, std::unique_ptr<SectionParser> parser); void AddSingleLineParser(const std::string& prefix, LineCallback callback); void AddSingleLineParser(const std::string& prefix, LineCallback callback); Loading