From 495cf53ca4a1139c724012d63c4e0cf08299266b Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Thu, 28 May 2009 01:42:41 +0000 Subject: 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 --- src/couchdb/couch_config.erl | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/couchdb/couch_config.erl') 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. -- cgit v1.2.3