Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 89310 invoked from network); 5 Jan 2009 10:39:04 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Jan 2009 10:39:04 -0000 Received: (qmail 73555 invoked by uid 500); 5 Jan 2009 10:39:04 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 73474 invoked by uid 500); 5 Jan 2009 10:39:03 -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 73460 invoked by uid 99); 5 Jan 2009 10:39:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Jan 2009 02:39:03 -0800 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; Mon, 05 Jan 2009 10:39:00 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 7D89A2388970; Mon, 5 Jan 2009 02:38:40 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r731521 - in /couchdb/trunk: src/couchdb/couch_config_writer.erl test/couch_config_writer_test.erl Date: Mon, 05 Jan 2009 10:38:39 -0000 To: commits@couchdb.apache.org From: jan@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090105103840.7D89A2388970@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: jan Date: Mon Jan 5 02:38:39 2009 New Revision: 731521 URL: http://svn.apache.org/viewvc?rev=731521&view=rev Log: Fix ini-section duplication. When we tried to assign a value to a config-item that happened to be set to that value already, a new and duplicated ini section with that config parameter was written to the ini file. Modified: couchdb/trunk/src/couchdb/couch_config_writer.erl couchdb/trunk/test/couch_config_writer_test.erl Modified: couchdb/trunk/src/couchdb/couch_config_writer.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_config_writer.erl?rev=731521&r1=731520&r2=731521&view=diff ============================================================================== --- couchdb/trunk/src/couchdb/couch_config_writer.erl (original) +++ couchdb/trunk/src/couchdb/couch_config_writer.erl Mon Jan 5 02:38:39 2009 @@ -42,11 +42,15 @@ % produce the contents for the config file NewFileContents = - case NewFileContents2 = save_loop({{SectionName, OptionList}, Value}, Lines, "", "", []) of + case {NewFileContents2, DoneOptions} = save_loop({{SectionName, OptionList}, Value}, Lines, "", "", []) of % we didn't change anything, that means we couldn't find a matching % [ini section] in which case we just append a new one. - OldFileContents -> - append_new_ini_section({{SectionName, OptionList}, Value}, OldFileContents); + {OldFileContents, DoneOptions} -> + % but only if we haven't actually written anything. + case lists:member(OptionList, DoneOptions) of + true -> OldFileContents; + _ -> append_new_ini_section({{SectionName, OptionList}, Value}, OldFileContents) + end; _ -> NewFileContents2 end, @@ -110,9 +114,9 @@ case lists:member(Option, DoneOptions) of % append Deferred Option false when Section == OldSection -> - NewFileContents ++ "\n" ++ Option ++ " = " ++ Value ++ "\n"; + {NewFileContents ++ "\n" ++ Option ++ " = " ++ Value ++ "\n", DoneOptions}; % we're out of new lines, just return the new file's contents - _ -> NewFileContents + _ -> {NewFileContents, DoneOptions} end. append_new_ini_section({{SectionName, Option}, Value}, OldFileContents) -> Modified: couchdb/trunk/test/couch_config_writer_test.erl URL: http://svn.apache.org/viewvc/couchdb/trunk/test/couch_config_writer_test.erl?rev=731521&r1=731520&r2=731521&view=diff ============================================================================== --- couchdb/trunk/test/couch_config_writer_test.erl (original) +++ couchdb/trunk/test/couch_config_writer_test.erl Mon Jan 5 02:38:39 2009 @@ -11,7 +11,8 @@ fun() -> replace_existing_variable3() end, fun() -> append_new_variable() end, fun() -> append_new_module() end, - fun() -> overwrite_variable_further_down() end + fun() -> overwrite_variable_further_down() end, + fun() -> double_append_new_section_bug() end ]. @@ -149,6 +150,33 @@ ", run_operation_and_compare_results(Contents, Expect, [{{"erlang", "option"}, "value"}, {{"erlang", "option2"}, "value2"}]). +double_append_new_section_bug() -> + % create file + Contents = "[section] +variable = value + +[another_section] +another_var = another_value + +[erlang] +option = value + +option2 = value2 +", + + Expect = "[section] +variable = value + +[another_section] +another_var = another_value + +[erlang] +option = value + +option2 = value2 +", + run_operation_and_compare_results(Contents, Expect, [{{"another_section", "another_var"}, "another_value"}]). + run_operation_and_compare_results(Contents, Expect, Config) when not is_list(Config) -> run_operation_and_compare_results(Contents, Expect, [Config]);