From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id AGCVI+M8MWDzaAAA0tVLHw (envelope-from ) for ; Sat, 20 Feb 2021 16:46:27 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id eIInH+M8MWAdagAAB5/wlQ (envelope-from ) for ; Sat, 20 Feb 2021 16:46:27 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E284213403 for ; Sat, 20 Feb 2021 17:46:26 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 312C627066; Sat, 20 Feb 2021 11:45:43 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 0561C26B9C for ; Sat, 20 Feb 2021 11:45:08 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id EC47660666; Sat, 20 Feb 2021 11:45:07 -0500 (EST) Received: (nullmailer pid 3956165 invoked by uid 1000); Sat, 20 Feb 2021 16:44:54 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/18] lib/open: pull _load_key_file out of _choose_database_path Date: Sat, 20 Feb 2021 12:44:33 -0400 Message-Id: <20210220164448.3956011-4-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210220164448.3956011-1-david@tethera.net> References: <20210220164448.3956011-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 7MDNXCPCCMFJHCJEZOMLD2JPNYV3FPZK X-Message-ID-Hash: 7MDNXCPCCMFJHCJEZOMLD2JPNYV3FPZK X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 0.48 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: E284213403 X-Spam-Score: 0.48 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9qzqrjfiAYLG Although this increases code duplication, it also increases flexibility in handling various combinations of missing config file and missing database. --- lib/open.cc | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index e5ef351e..e1ad957f 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -183,27 +183,18 @@ _db_dir_exists (const char *database_path, char **message) static notmuch_status_t _choose_database_path (void * ctx, - const char *config_path, const char *profile, - GKeyFile **key_file, + GKeyFile *key_file, const char **database_path, bool *split, char **message) { - notmuch_status_t status; - - status =_load_key_file (config_path, profile, key_file); - if (status) { - *message = strdup ("Error: cannot load config file.\n"); - return status; - } - if (! *database_path) { *database_path = getenv ("NOTMUCH_DATABASE"); } - if (! *database_path && *key_file) - *database_path = g_key_file_get_value (*key_file, "database", "path", NULL); + if (! *database_path && key_file) + *database_path = g_key_file_get_value (key_file, "database", "path", NULL); if (! *database_path) { *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile); @@ -482,8 +473,14 @@ notmuch_database_open_with_config (const char *database_path, goto DONE; } - if ((status = _choose_database_path (local, config_path, profile, - &key_file, &database_path, &split, + status =_load_key_file (config_path, profile, &key_file); + if (status) { + message = strdup ("Error: cannot load config file.\n"); + goto DONE; + } + + if ((status = _choose_database_path (local, profile, key_file, + &database_path, &split, &message))) goto DONE; @@ -569,9 +566,14 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - if ((status = _choose_database_path (local, config_path, profile, - &key_file, &database_path, &split, - &message))) + status =_load_key_file (config_path, profile, &key_file); + if (status) { + message = strdup ("Error: cannot load config file.\n"); + goto DONE; + } + + if ((status = _choose_database_path (local, profile, key_file, + &database_path, &split, &message))) goto DONE; status = _db_dir_exists (database_path, &message); -- 2.30.0