couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
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 GMT
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]);



Mime
View raw message