From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oNmWErzaQGB1bgAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:03:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id yPNxDrzaQGCkIAAA1q6Kng (envelope-from ) for ; Thu, 04 Mar 2021 13:03:56 +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 DF16815FCA for ; Thu, 4 Mar 2021 14:03:55 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 47D0027C33; Thu, 4 Mar 2021 08:02:26 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id A91CF26C3E for ; Thu, 4 Mar 2021 08:02:02 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id A11D25FA96; Thu, 4 Mar 2021 08:02:02 -0500 (EST) Received: (nullmailer pid 4047166 invoked by uid 1000); Thu, 04 Mar 2021 13:01:45 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/27] lib/open: pull _load_key_file out of _choose_database_path Date: Thu, 4 Mar 2021 09:01:15 -0400 Message-Id: <20210304130139.4046183-4-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304130139.4046183-1-david@tethera.net> References: <20210304130139.4046183-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: SOIJ7VQJ2CWKX5HCPCW62PRA2PFMDE2H X-Message-ID-Hash: SOIJ7VQJ2CWKX5HCPCW62PRA2PFMDE2H 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=1614863036; 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=N7e5BNVKtfu/BoWtSFM/nGN7kqPwOPKM37PorcVRgOk=; b=Uik48y11ask57IU2WLLvqVo6sHXfKDDfJ4l0qJrZny6iHotraG2GrGujipg9bKU87v/WZl VD7UJzIGl9OnR8L8EzhuHRYOmwXHmJOx4nywXzWGBMAdnjDsa1dcDw6Zdm/he0ib19jV8c /K2vJmxIItS9h5+M4YRxW0A+pQx2TuLVx46Fp/cwJcU7O6+uanKV0Re4dX/EdZu+OVxoK9 bUJs6TvyJqTwHZ8TXInQNVViVJlToYvVKxP1VIjcqyGYyIm+s5PuzUM9aFA53xsvVCe7Jg 8GbUis/JwBHK1+970a3SkLfMt+HcLxInIKSAH6+qqKQqtTSqg9ds83mIkZQi2g== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614863036; a=rsa-sha256; cv=none; b=GdWfE4d69Hz9Qiub16Y0mygLGG43EitU3XZM2V6mlRS8zaxOn+fZlknUnjq1cX6cVzL6BR /z7nGmXWQlZA2mp1NPRibZUf3/kUQiJmazskwemNrZvogNxfsTk5MJYmLbFT/crgzKdzG4 c9PhnU+7Vgjkqj56qs3/F9dOVtCc7EPhfUJZ7beO2mTXYdcdV+VH6JOn/CYDvEtiDVA16J 0V3Ug2S6QW7HxCRemvFGQvjcLyrGRSa91cdbJIa6eWErD+ynoGAjrc3qk18oiAzxRYeUDo QBGYEzU/hv4vEKq4MoZQt++jIVLJ6n1bNyTWYbec+/6phNP4ppaGTqZpn3Rtmg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=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.96 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: DF16815FCA X-Spam-Score: -0.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZvtbSKG3n8mp 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.1