This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch config-delete-reload
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 4610d12d851829a3e04561a33689eb90b9f5e137
Author: Jay Doane <[email protected]>
AuthorDate: Wed Oct 18 17:48:14 2023 -0700

    Reload default config value from disk on delete
    
    When a key is deleted, reload any default back into memory.
    
    This breaks the existing semantics as demonstrated by how the test
    must change in order to pass now.
---
 src/config/src/config.erl        | 7 +++++++
 src/config/test/config_tests.erl | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/config/src/config.erl b/src/config/src/config.erl
index 3431e9a56..5cb2e6b02 100644
--- a/src/config/src/config.erl
+++ b/src/config/src/config.erl
@@ -326,6 +326,13 @@ handle_call({delete, Sec, Key, Persist, Reason}, _From, 
Config) ->
         "~p: [~s] ~s deleted for reason ~p",
         [?MODULE, Sec, Key, Reason]
     ),
+    DiskKVs = parse_ini_files(Config#config.ini_files),
+    case dict:find({Sec, Key}, DiskKVs) of
+        {ok, DiskVal} ->
+            true = ets:insert(?MODULE, {{Sec, Key}, DiskVal});
+        error ->
+            ok
+    end,
     ConfigDeleteReturn =
         case {Persist, Config#config.write_filename} of
             {true, undefined} ->
diff --git a/src/config/test/config_tests.erl b/src/config/test/config_tests.erl
index dc83d2c72..ff7fcc546 100644
--- a/src/config/test/config_tests.erl
+++ b/src/config/test/config_tests.erl
@@ -438,7 +438,7 @@ should_write_changes(_, _) ->
         ?assertEqual(ok, config:set("httpd", "port", "8080")),
         ?assertEqual("8080", config:get("httpd", "port")),
         ?assertEqual(ok, config:delete("httpd", "bind_address")),
-        ?assertEqual(undefined, config:get("httpd", "bind_address"))
+        ?assertEqual("127.0.0.1", config:get("httpd", "bind_address"))
     end).
 
 should_ensure_default_wasnt_modified(_, _) ->

Reply via email to