From 358f2a9405e2cbb0700bce2046e5569e33594127 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Sun, 19 Jul 2009 21:29:33 +0000 Subject: protect against empty (=deleted) values. Closes COUCHDB-355 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@795630 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_config.erl | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl index d590c321..c6fffe49 100644 --- a/src/couchdb/couch_config.erl +++ b/src/couchdb/couch_config.erl @@ -78,7 +78,7 @@ delete(Section, Key) -> delete(Section, Key, Persist) when is_binary(Section) and is_binary(Key) -> delete(?b2l(Section), ?b2l(Key), Persist); delete(Section, Key, Persist) -> - ?MODULE:set(Section, Key, "", Persist). + gen_server:call(?MODULE, {delete, Section, Key, Persist}). register(Fun) -> @@ -130,6 +130,18 @@ handle_call({set, Sec, Key, Val, Persist}, _From, Config) -> end, [catch F(Sec, Key, Val) || {_Pid, F} <- Config#config.notify_funs], {reply, ok, Config}; +handle_call({delete, Sec, Key, Persist}, _From, Config) -> + true = ets:delete(?MODULE, {Sec,Key}), + case {Persist, Config#config.write_filename} of + {true, undefined} -> + ok; + {true, FileName} -> + couch_config_writer:save_to_file({{Sec, Key}, ""}, FileName); + _ -> + ok + end, + [catch F(Sec, Key, deleted) || {_Pid, F} <- Config#config.notify_funs], + {reply, ok, Config}; handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) -> erlang:monitor(process, Pid), % convert 1 and 2 arity to 3 arity @@ -194,10 +206,15 @@ parse_ini_file(IniFile) -> {ok, [ValueName|LineValues]} -> % yeehaw, got a line! RemainingLine = couch_util:implode(LineValues, "="), % removes comments - {ok, [LineValue | _Rest]} = - regexp:split(RemainingLine, " ;|\t;"), - {AccSectionName, - [{{AccSectionName, ValueName}, LineValue} | AccValues]} + case regexp:split(RemainingLine, " ;|\t;") of + {ok, [[]]} -> + % empty line means delete this key + ets:delete(?MODULE, {AccSectionName, ValueName}), + {AccSectionName, AccValues}; + {ok, [LineValue | _Rest]} -> + {AccSectionName, + [{{AccSectionName, ValueName}, LineValue} | AccValues]} + end end end end, {"", []}, Lines), -- cgit v1.2.3