summaryrefslogtreecommitdiff
path: root/src/couchdb/couch_config.erl
diff options
context:
space:
mode:
authorAdam Kocoloski <kocolosk@apache.org>2009-05-28 01:42:41 +0000
committerAdam Kocoloski <kocolosk@apache.org>2009-05-28 01:42:41 +0000
commit495cf53ca4a1139c724012d63c4e0cf08299266b (patch)
tree6aa305c515fa48eec2477635014eb2fb6dc204a6 /src/couchdb/couch_config.erl
parentdbabd6616febf5585be567695dd61a27bc463092 (diff)
refactor load_ini_file so it can be called from another process
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@779394 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_config.erl')
-rw-r--r--src/couchdb/couch_config.erl16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/couchdb/couch_config.erl b/src/couchdb/couch_config.erl
index d5b93201..dcdbc9eb 100644
--- a/src/couchdb/couch_config.erl
+++ b/src/couchdb/couch_config.erl
@@ -81,7 +81,10 @@ register(Fun, Pid) ->
%% @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 @@ handle_call({register, Fun, Pid}, _From, #config{notify_funs=PidFuns}=Config) ->
%% @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 @@ load_ini_file(IniFile) ->
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.