From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id JWKKBEIRbWA2IAEAgWs5BA (envelope-from ) for ; Wed, 07 Apr 2021 03:56:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id AGwPOUERbWB6QwAAbx9fmQ (envelope-from ) for ; Wed, 07 Apr 2021 01:56:17 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 A5885AE35 for ; Wed, 7 Apr 2021 03:56:17 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 95E3929035; Tue, 6 Apr 2021 21:55:49 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 7284C1FAC2 for ; Tue, 6 Apr 2021 21:55:40 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 695BA5FA96; Tue, 6 Apr 2021 21:55:40 -0400 (EDT) Received: (nullmailer pid 2964211 invoked by uid 1000); Wed, 07 Apr 2021 01:55:35 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 04/28] lib/open: pull _load_key_file out of _choose_database_path Date: Tue, 6 Apr 2021 22:55:06 -0300 Message-Id: <20210407015530.2964017-5-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210407015530.2964017-1-david@tethera.net> References: <20210407015530.2964017-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: LFZPCJCQTOVFNO36MBNKV4QGBPHUSUPL X-Message-ID-Hash: LFZPCJCQTOVFNO36MBNKV4QGBPHUSUPL 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1617760577; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=rTRWeddNEX2R9GH7Jp2ICmt3d3H3nU9bi6TA/VYIvqQ=; b=GiEf0kTQIb9y/7Nwm+Az8E24tMArccXpDqem4Do/qrMbrkYdmPeL52LHXF2+VD2AR9GZrr vwtO9n5U5XEgjGxctF58Ax2tK2cfjCCVn2axws8arWaL3EYvh7oiUs6+tCoD9LKtFzpO9C j44TSGldapS7o5jVDDuCa75p2bkUXTlQDkuT0mVQ5PWUqbuRFVTEuLflhHAoHoGiizo+Io yQRbOEOBt0J1nL+SGzy3ij6B8mEXPIqcX23Zo//FHOk7NTWcCIyo4lYluJ1RRct2JbrE+z dRMZul1GP9qKBbbyfdVQjJnRhY6y3b+16Djl8my34HWNpCbe970dH+yn+Z3h6w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1617760577; a=rsa-sha256; cv=none; b=hjWsd9EGe4nSR2aqP4TZ0jyHzYe+9hjyJnnzhuNZdo8geovevPOnwO1i8vzWi2Qir5C8HM zsZbBFnLqo+VHwob2hHwOQ3VduniTdR7GRczPy21P8j9JG3v6yzJy8m87ODNT+il2mlNXm W+WcaEqO1t+IScrnR7f6Mrx9wmHFg2TLHg76pjSSCUkYKt33Uv416bPfhn4B4Ups7rYF4T JNBTSUCVXCjiLjZkp7HGQh2MBNBL54qARjqF5uHD7vVcX+Moe4THLCpjf6FvjEnKMLW0SC 7kNFFWV0DpUYpqGP2LOsv5Qx6kKC9OgMllvxRwcS6zxFYI70ftgM1tQcX1pr1w== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: 0.02 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: A5885AE35 X-Spam-Score: 0.02 X-Migadu-Scanner: scn0.migadu.com X-TUID: u6mIaxANYApQ 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, 18 insertions(+), 18 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index dc191d64..9bb313da 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) { - char *path = g_key_file_get_value (*key_file, "database", "path", NULL); + if (! *database_path && key_file) { + char *path = g_key_file_get_value (key_file, "database", "path", NULL); if (path) { *database_path = talloc_strdup (ctx, path); g_free (path); @@ -500,8 +491,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; @@ -591,11 +588,14 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - _init_libs (); + 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, config_path, profile, - &key_file, &database_path, &split, - &message))) + if ((status = _choose_database_path (local, profile, key_file, + &database_path, &split, &message))) goto DONE; status = _db_dir_exists (database_path, &message); -- 2.30.2