Return-Path: Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: (qmail 34643 invoked from network); 28 May 2009 01:52:52 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 28 May 2009 01:52:52 -0000 Received: (qmail 4628 invoked by uid 500); 28 May 2009 01:43:04 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 4608 invoked by uid 500); 28 May 2009 01:43:04 -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 4599 invoked by uid 99); 28 May 2009 01:43:03 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 May 2009 01:43:03 +0000 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; Thu, 28 May 2009 01:43:01 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C4C5223888D0; Thu, 28 May 2009 01:42:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r779394 - /couchdb/trunk/src/couchdb/couch_config.erl Date: Thu, 28 May 2009 01:42:41 -0000 To: commits@couchdb.apache.org From: kocolosk@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090528014241.C4C5223888D0@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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.