From ef6a5e8545c4457effa7afd4329efc333c83b35e Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Sat, 2 Mar 2019 09:59:09 -0500 Subject: [PATCH] Merge #15335: Fix lack of warning of unrecognized section names 1a7ba84e11 Fix lack of warning of unrecognized section names (Akio Nakamura) Pull request description: In #14708, It was introduced that to warn when unrecognized section names are exist in the config file. But ```m_config_sections.clear()``` in ```ArgsManager::ReadConfigStream()``` is called every time when reading each configuration file, so it can warn about only last reading file if ```includeconf``` exists. This PR fix lack of warning by collecting all section names by moving ```m_config_sections.clear()``` to ```ArgsManager::ReadConfigFiles()``` . Also add a test code to confirm this situation. Tree-SHA512: 26aa0cbe3e4ae2e58cbe73d4492ee5cf465fd4c3e5df2c8ca7e282b627df9e637267af1e3816386b1dc6db2398b31936925ce0e432219fec3a9b3398f01e3e65 --- src/test/util_tests.cpp | 3 ++- src/util/system.cpp | 9 +++++---- src/util/system.h | 9 ++++++++- test/functional/feature_config_args.py | 2 ++ 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index d1b5e24c5eaf1a..47a06ff4028a79 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -132,9 +132,10 @@ struct TestArgsManager : public ArgsManager { LOCK(cs_args); m_config_args.clear(); + m_config_sections.clear(); } std::string error; - BOOST_REQUIRE(ReadConfigStream(streamConfig, error)); + BOOST_REQUIRE(ReadConfigStream(streamConfig, "", error)); } void SetNetworkOnlyArg(const std::string arg) { diff --git a/src/util/system.cpp b/src/util/system.cpp index df605a6046bf67..3a4a48e070d6dc 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -927,11 +927,11 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect return true; } -bool ArgsManager::ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys) +bool ArgsManager::ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys) { LOCK(cs_args); std::vector> options; - if (!GetConfigOptions(stream, error, options)) { + if (!GetConfigOptions(stream, filepath, error, options)) { return false; } for (const std::pair& option : options) { @@ -962,13 +962,14 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) { LOCK(cs_args); m_config_args.clear(); + m_config_sections.clear(); } const std::string confPath = GetArg("-conf", BITCOIN_CONF_FILENAME); fsbridge::ifstream stream(GetConfigFile(confPath)); if (stream.good()) { - if (!ReadConfigStream(stream, error, ignore_invalid_keys)) { + if (!ReadConfigStream(stream, confPath, error, ignore_invalid_keys)) { return false; } // if there is an -includeconf in the override args, but it is empty, that means the user @@ -999,7 +1000,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys) for (const std::string& to_include : includeconf) { fsbridge::ifstream include_config(GetConfigFile(to_include)); if (include_config.good()) { - if (!ReadConfigStream(include_config, error, ignore_invalid_keys)) { + if (!ReadConfigStream(include_config, to_include, error, ignore_invalid_keys)) { return false; } LogPrintf("Included configuration file %s\n", to_include.c_str()); diff --git a/src/util/system.h b/src/util/system.h index 8289c164b33a59..f1d7381dde7ae1 100644 --- a/src/util/system.h +++ b/src/util/system.h @@ -157,6 +157,13 @@ enum class OptionsCategory { HIDDEN // Always the last option to avoid printing these in the help }; +struct SectionInfo +{ + std::string m_name; + std::string m_file; + int m_line; +}; + class ArgsManager { protected: @@ -178,7 +185,7 @@ class ArgsManager std::set m_network_only_args GUARDED_BY(cs_args); std::map> m_available_args GUARDED_BY(cs_args); - [[nodiscard]] bool ReadConfigStream(std::istream& stream, std::string& error, bool ignore_invalid_keys = false); + [[nodiscard]] bool ReadConfigStream(std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys = false); public: ArgsManager(); diff --git a/test/functional/feature_config_args.py b/test/functional/feature_config_args.py index feef4e7f5b7406..446456f26a3555 100755 --- a/test/functional/feature_config_args.py +++ b/test/functional/feature_config_args.py @@ -45,6 +45,8 @@ def test_config_file_parser(self): with open(inc_conf_file_path, 'w', encoding='utf-8') as conf: conf.write('') # clear + with open(inc_conf_file2_path, 'w', encoding='utf-8') as conf: + conf.write('') # clear def test_log_buffer(self):