couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kocol...@apache.org
Subject svn commit: r779394 - /couchdb/trunk/src/couchdb/couch_config.erl
Date Thu, 28 May 2009 01:42:41 GMT
Author: kocolosk
Date: Thu May 28 01:42:41 2009
New Revision: 779394

URL: http://svn.apache.org/viewvc?rev=779394&view=rev
Log:
refactor load_ini_file so it can be called from another process

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=779394&r1=779393&r2=779394&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_config.erl (original)
+++ couchdb/trunk/src/couchdb/couch_config.erl Thu May 28 01:42:41 2009
@@ -81,7 +81,10 @@
 %% @doc Creates a new ets table of the type "set".
 init(IniFiles) ->
     ets:new(?MODULE, [named_table, set, protected]),
-    [ok = load_ini_file(IniFile) || IniFile <- IniFiles],
+    lists:map(fun(IniFile) ->
+        {ok, ParsedIniValues} = parse_ini_file(IniFile),
+        ets:insert(?MODULE, ParsedIniValues)
+    end, IniFiles),
     {ok, #config{write_filename=lists:last(IniFiles)}}.
 
 handle_call({set, KVs, Persist}, _From, Config) ->
@@ -114,6 +117,13 @@
 %% @spec load_ini_file(IniFile::filename()) -> ok
 %% @doc Parses an ini file and stores Key/Value Pairs into the ets table.
 load_ini_file(IniFile) ->
+    {ok, KVs} = parse_ini_file(IniFile),
+    gen_server:call(?MODULE, {set, KVs, false}).
+
+%% @spec load_ini_file(IniFile::filename()) -> {ok, [KV]}
+%%       KV = {{Section::string(), Key::string()}, Value::String()}
+%% @throws {startup_error, Msg::string()}
+parse_ini_file(IniFile) ->
     IniFilename = couch_util:abs_pathname(IniFile),
     IniBin =
     case file:read_file(IniFilename) of
@@ -151,9 +161,7 @@
                 end
             end
         end, {"", []}, Lines),
-
-        [ets:insert(?MODULE, {Key, Value}) || {Key, Value} <- ParsedIniValues],
-    ok.
+    {ok, ParsedIniValues}.
 
 % Unused gen_server behaviour API functions that we need to declare.
 



Mime
View raw message