summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-07-19 21:29:33 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-07-19 21:29:33 +0000
commit358f2a9405e2cbb0700bce2046e5569e33594127 (patch)
tree38566c0fabde02e03177c683562ad4ad41873ee8 /src
parentd04d64e6eedf41f25b39a3366bc3dc4534843c52 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_config.erl27
1 files changed, 22 insertions, 5 deletions
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),