Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 53773 invoked from network); 19 Jul 2009 21:28:56 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Jul 2009 21:28:56 -0000 Received: (qmail 43051 invoked by uid 500); 19 Jul 2009 21:30:02 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 42954 invoked by uid 500); 19 Jul 2009 21:30:02 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 42945 invoked by uid 99); 19 Jul 2009 21:30:02 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Jul 2009 21:30:02 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 19 Jul 2009 21:30:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0B8F42388900; Sun, 19 Jul 2009 21:29:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r795630 - /couchdb/trunk/src/couchdb/couch_config.erl Date: Sun, 19 Jul 2009 21:29:39 -0000 To: commits@couchdb.apache.org From: kocolosk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090719212940.0B8F42388900@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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),