Author: kocolosk
Date: Sun Jul 19 21:29:33 2009
New Revision: 795630
URL: http://svn.apache.org/viewvc?rev=795630&view=rev
Log:
protect against empty (=deleted) values. Closes COUCHDB-355
Modified:
couchdb/trunk/src/couchdb/couch_config.erl
Modified: couchdb/trunk/src/couchdb/couch_config.erl
URL:
http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_config.erl?rev=795630&r1=795629&r2=795630&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_config.erl (original)
+++ couchdb/trunk/src/couchdb/couch_config.erl Sun Jul 19 21:29:33 2009
@@ -78,7 +78,7 @@
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 @@
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 @@
{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),