mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
chain: ensure updateRwSetting
doesn't update to a null settings
Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
parent
c8e2eeeffb
commit
df601993f2
2 changed files with 10 additions and 4 deletions
|
@ -356,6 +356,8 @@ public:
|
||||||
virtual common::SettingsValue getRwSetting(const std::string& name) = 0;
|
virtual common::SettingsValue getRwSetting(const std::string& name) = 0;
|
||||||
|
|
||||||
//! Updates a setting in <datadir>/settings.json.
|
//! Updates a setting in <datadir>/settings.json.
|
||||||
|
//! Null can be passed to erase the setting. There is intentionally no
|
||||||
|
//! support for writing null values to settings.json.
|
||||||
//! Depending on the action returned by the update function, this will either
|
//! Depending on the action returned by the update function, this will either
|
||||||
//! update the setting in memory or write the updated settings to disk.
|
//! update the setting in memory or write the updated settings to disk.
|
||||||
virtual bool updateRwSetting(const std::string& name, const SettingsUpdate& update_function) = 0;
|
virtual bool updateRwSetting(const std::string& name, const SettingsUpdate& update_function) = 0;
|
||||||
|
|
|
@ -819,10 +819,14 @@ public:
|
||||||
{
|
{
|
||||||
std::optional<interfaces::SettingsAction> action;
|
std::optional<interfaces::SettingsAction> action;
|
||||||
args().LockSettings([&](common::Settings& settings) {
|
args().LockSettings([&](common::Settings& settings) {
|
||||||
auto* ptr_value = common::FindKey(settings.rw_settings, name);
|
if (auto* value = common::FindKey(settings.rw_settings, name)) {
|
||||||
// Create value if it doesn't exist
|
action = update_settings_func(*value);
|
||||||
auto& value = ptr_value ? *ptr_value : settings.rw_settings[name];
|
if (value->isNull()) settings.rw_settings.erase(name);
|
||||||
action = update_settings_func(value);
|
} else {
|
||||||
|
UniValue new_value;
|
||||||
|
action = update_settings_func(new_value);
|
||||||
|
if (!new_value.isNull()) settings.rw_settings[name] = std::move(new_value);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (!action) return false;
|
if (!action) return false;
|
||||||
// Now dump value to disk if requested
|
// Now dump value to disk if requested
|
||||||
|
|
Loading…
Add table
Reference in a new issue