@@ -354,23 +354,19 @@ const std::set<std::string> ArgsManager::GetUnsuitableSectionOnlyArgs() const
354
354
return unsuitables;
355
355
}
356
356
357
-
358
- const std::set<std::string> ArgsManager::GetUnrecognizedSections () const
357
+ const std::list<SectionInfo> ArgsManager::GetUnrecognizedSections () const
359
358
{
360
359
// Section names to be recognized in the config file.
361
360
static const std::set<std::string> available_sections{
362
361
CBaseChainParams::REGTEST,
363
362
CBaseChainParams::TESTNET,
364
363
CBaseChainParams::MAIN
365
364
};
366
- std::set<std::string> diff;
367
365
368
366
LOCK (cs_args);
369
- std::set_difference (
370
- m_config_sections.begin (), m_config_sections.end (),
371
- available_sections.begin (), available_sections.end (),
372
- std::inserter (diff, diff.end ()));
373
- return diff;
367
+ std::list<SectionInfo> unrecognized = m_config_sections;
368
+ unrecognized.remove_if ([](const SectionInfo& appeared){ return available_sections.find (appeared.m_name ) != available_sections.end (); });
369
+ return unrecognized;
374
370
}
375
371
376
372
void ArgsManager::SelectConfigNetwork (const std::string& network)
@@ -794,7 +790,7 @@ static std::string TrimString(const std::string& str, const std::string& pattern
794
790
return str.substr (front, end - front + 1 );
795
791
}
796
792
797
- static bool GetConfigOptions (std::istream& stream, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::set<std::string >& sections)
793
+ static bool GetConfigOptions (std::istream& stream, const std::string& filepath, std::string& error, std::vector<std::pair<std::string, std::string>>& options, std::list<SectionInfo >& sections)
798
794
{
799
795
std::string str, prefix;
800
796
std::string::size_type pos;
@@ -810,7 +806,7 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
810
806
if (!str.empty ()) {
811
807
if (*str.begin () == ' [' && *str.rbegin () == ' ]' ) {
812
808
const std::string section = str.substr (1 , str.size () - 2 );
813
- sections.insert ( section);
809
+ sections.emplace_back (SectionInfo{ section, filepath, linenr} );
814
810
prefix = section + ' .' ;
815
811
} else if (*str.begin () == ' -' ) {
816
812
error = strprintf (" parse error on line %i: %s, options in configuration file must be specified without leading -" , linenr, str);
@@ -823,8 +819,8 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
823
819
return false ;
824
820
}
825
821
options.emplace_back (name, value);
826
- if ((pos = name.rfind (' .' )) != std::string::npos) {
827
- sections.insert ( name.substr (0 , pos));
822
+ if ((pos = name.rfind (' .' )) != std::string::npos && prefix. length () <= pos ) {
823
+ sections.emplace_back (SectionInfo{ name.substr (0 , pos), filepath, linenr} );
828
824
}
829
825
} else {
830
826
error = strprintf (" parse error on line %i: %s" , linenr, str);
@@ -839,12 +835,11 @@ static bool GetConfigOptions(std::istream& stream, std::string& error, std::vect
839
835
return true ;
840
836
}
841
837
842
- bool ArgsManager::ReadConfigStream (std::istream& stream, std::string& error, bool ignore_invalid_keys)
838
+ bool ArgsManager::ReadConfigStream (std::istream& stream, const std::string& filepath, std::string& error, bool ignore_invalid_keys)
843
839
{
844
840
LOCK (cs_args);
845
841
std::vector<std::pair<std::string, std::string>> options;
846
- m_config_sections.clear ();
847
- if (!GetConfigOptions (stream, error, options, m_config_sections)) {
842
+ if (!GetConfigOptions (stream, filepath, error, options, m_config_sections)) {
848
843
return false ;
849
844
}
850
845
for (const std::pair<std::string, std::string>& option : options) {
@@ -875,14 +870,15 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
875
870
{
876
871
LOCK (cs_args);
877
872
m_config_args.clear ();
873
+ m_config_sections.clear ();
878
874
}
879
875
880
876
const std::string confPath = GetArg (" -conf" , BITCOIN_CONF_FILENAME);
881
877
fsbridge::ifstream stream (GetConfigFile (confPath));
882
878
883
879
// ok to not have a config file
884
880
if (stream.good ()) {
885
- if (!ReadConfigStream (stream, error, ignore_invalid_keys)) {
881
+ if (!ReadConfigStream (stream, confPath, error, ignore_invalid_keys)) {
886
882
return false ;
887
883
}
888
884
// if there is an -includeconf in the override args, but it is empty, that means the user
@@ -913,7 +909,7 @@ bool ArgsManager::ReadConfigFiles(std::string& error, bool ignore_invalid_keys)
913
909
for (const std::string& to_include : includeconf) {
914
910
fsbridge::ifstream include_config (GetConfigFile (to_include));
915
911
if (include_config.good ()) {
916
- if (!ReadConfigStream (include_config, error, ignore_invalid_keys)) {
912
+ if (!ReadConfigStream (include_config, to_include, error, ignore_invalid_keys)) {
917
913
return false ;
918
914
}
919
915
LogPrintf (" Included configuration file %s\n " , to_include.c_str ());
0 commit comments