Changeset View
Changeset View
Standalone View
Standalone View
src/util/settings.cpp
Show First 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | namespace { | ||||
} | } | ||||
} // namespace | } // namespace | ||||
SettingsValue GetSetting(const Settings &settings, const std::string §ion, | SettingsValue GetSetting(const Settings &settings, const std::string §ion, | ||||
const std::string &name, | const std::string &name, | ||||
bool ignore_default_section_config, | bool ignore_default_section_config, | ||||
bool get_chain_name) { | bool get_chain_name) { | ||||
SettingsValue result; | SettingsValue result; | ||||
// Done merging any more settings sources. | |||||
bool done = false; | |||||
MergeSettings( | MergeSettings( | ||||
settings, section, name, [&](SettingsSpan span, Source source) { | settings, section, name, [&](SettingsSpan span, Source source) { | ||||
// Weird behavior preserved for backwards compatibility: Apply | // Weird behavior preserved for backwards compatibility: Apply | ||||
// negated setting even if non-negated setting would be ignored. A | // negated setting even if non-negated setting would be ignored. A | ||||
// negated value in the default section is applied to network | // negated value in the default section is applied to network | ||||
// specific options, even though normal non-negated values there | // specific options, even though normal non-negated values there | ||||
// would be ignored. | // would be ignored. | ||||
const bool never_ignore_negated_setting = span.last_negated(); | const bool never_ignore_negated_setting = span.last_negated(); | ||||
Show All 11 Lines | MergeSettings( | ||||
// Weird behavior preserved for backwards compatibility: Negated | // Weird behavior preserved for backwards compatibility: Negated | ||||
// -regtest and -testnet arguments which you would expect to | // -regtest and -testnet arguments which you would expect to | ||||
// override values set in the configuration file are currently | // override values set in the configuration file are currently | ||||
// accepted but silently ignored. It would be better to apply these | // accepted but silently ignored. It would be better to apply these | ||||
// just like other negated values, or at least warn they are | // just like other negated values, or at least warn they are | ||||
// ignored. | // ignored. | ||||
const bool skip_negated_command_line = get_chain_name; | const bool skip_negated_command_line = get_chain_name; | ||||
if (done) { | |||||
return; | |||||
} | |||||
// Ignore settings in default config section if requested. | // Ignore settings in default config section if requested. | ||||
if (ignore_default_section_config && | if (ignore_default_section_config && | ||||
source == Source::CONFIG_FILE_DEFAULT_SECTION && | source == Source::CONFIG_FILE_DEFAULT_SECTION && | ||||
!never_ignore_negated_setting) { | !never_ignore_negated_setting) { | ||||
return; | return; | ||||
} | } | ||||
// Skip negated command line settings. | // Skip negated command line settings. | ||||
if (skip_negated_command_line && span.last_negated()) { | if (skip_negated_command_line && span.last_negated()) { | ||||
return; | return; | ||||
} | } | ||||
// Stick with highest priority value, keeping result if already set. | |||||
if (!result.isNull()) { | |||||
return; | |||||
} | |||||
if (!span.empty()) { | if (!span.empty()) { | ||||
result = reverse_precedence ? span.begin()[0] : span.end()[-1]; | result = reverse_precedence ? span.begin()[0] : span.end()[-1]; | ||||
done = true; | |||||
} else if (span.last_negated()) { | } else if (span.last_negated()) { | ||||
result = false; | result = false; | ||||
done = true; | |||||
} | } | ||||
}); | }); | ||||
return result; | return result; | ||||
} | } | ||||
std::vector<SettingsValue> GetSettingsList(const Settings &settings, | std::vector<SettingsValue> GetSettingsList(const Settings &settings, | ||||
const std::string §ion, | const std::string §ion, | ||||
const std::string &name, | const std::string &name, | ||||
bool ignore_default_section_config) { | bool ignore_default_section_config) { | ||||
std::vector<SettingsValue> result; | std::vector<SettingsValue> result; | ||||
bool result_complete = false; | // Done merging any more settings sources. | ||||
bool done = false; | |||||
bool prev_negated_empty = false; | bool prev_negated_empty = false; | ||||
MergeSettings( | MergeSettings( | ||||
settings, section, name, [&](SettingsSpan span, Source source) { | settings, section, name, [&](SettingsSpan span, Source source) { | ||||
// Weird behavior preserved for backwards compatibility: Apply | // Weird behavior preserved for backwards compatibility: Apply | ||||
// config file settings even if negated on command line. Negating a | // config file settings even if negated on command line. Negating a | ||||
// setting on command line will ignore earlier settings on the | // setting on command line will ignore earlier settings on the | ||||
// command line and ignore settings in the config file, unless the | // command line and ignore settings in the config file, unless the | ||||
// negated command line value is followed by non-negated value, in | // negated command line value is followed by non-negated value, in | ||||
// which case config file settings will be brought back from the | // which case config file settings will be brought back from the | ||||
// dead (but earlier command line settings will still be ignored). | // dead (but earlier command line settings will still be ignored). | ||||
const bool add_zombie_config_values = | const bool add_zombie_config_values = | ||||
(source == Source::CONFIG_FILE_NETWORK_SECTION || | (source == Source::CONFIG_FILE_NETWORK_SECTION || | ||||
source == Source::CONFIG_FILE_DEFAULT_SECTION) && | source == Source::CONFIG_FILE_DEFAULT_SECTION) && | ||||
!prev_negated_empty; | !prev_negated_empty; | ||||
// Ignore settings in default config section if requested. | // Ignore settings in default config section if requested. | ||||
if (ignore_default_section_config && | if (ignore_default_section_config && | ||||
source == Source::CONFIG_FILE_DEFAULT_SECTION) { | source == Source::CONFIG_FILE_DEFAULT_SECTION) { | ||||
return; | return; | ||||
} | } | ||||
// Add new settings to the result if isn't already complete, or if | // Add new settings to the result if isn't already complete, or if | ||||
// the values are zombies. | // the values are zombies. | ||||
if (!result_complete || add_zombie_config_values) { | if (!done || add_zombie_config_values) { | ||||
for (const auto &value : span) { | for (const auto &value : span) { | ||||
if (value.isArray()) { | if (value.isArray()) { | ||||
result.insert(result.end(), value.getValues().begin(), | result.insert(result.end(), value.getValues().begin(), | ||||
value.getValues().end()); | value.getValues().end()); | ||||
} else { | } else { | ||||
result.push_back(value); | result.push_back(value); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// If a setting was negated, or if a setting was forced, set | // If a setting was negated, or if a setting was forced, set done to | ||||
// result_complete to true to ignore any later lower priority | // true to ignore any later lower priority settings. | ||||
// settings. | done |= span.negated() > 0 || source == Source::FORCED; | ||||
result_complete |= span.negated() > 0 || source == Source::FORCED; | |||||
// Update the negated and empty state used for the zombie values | // Update the negated and empty state used for the zombie values | ||||
// check. | // check. | ||||
prev_negated_empty |= span.last_negated() && result.empty(); | prev_negated_empty |= span.last_negated() && result.empty(); | ||||
}); | }); | ||||
return result; | return result; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 46 Lines • Show Last 20 Lines |