From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id oK0rLPhU8l/zfQAA0tVLHw (envelope-from ) for ; Sun, 03 Jan 2021 23:36:24 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id 0H4LKPhU8l+MPQAA1q6Kng (envelope-from ) for ; Sun, 03 Jan 2021 23:36:24 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 6C1FE940222 for ; Sun, 3 Jan 2021 23:36:24 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id BA29929D40; Sun, 3 Jan 2021 18:36:04 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id E3E4329CB2 for ; Sun, 3 Jan 2021 18:35:59 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id DB5BB5FF47; Sun, 3 Jan 2021 18:35:59 -0500 (EST) Received: (nullmailer pid 126254 invoked by uid 1000); Sun, 03 Jan 2021 23:35:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 30/36] lib/open: factor out first part of open Date: Sun, 3 Jan 2021 19:35:41 -0400 Message-Id: <20210103233547.122707-31-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210103233547.122707-1-david@tethera.net> References: <20210103233547.122707-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: BOAQZVMBH3337XENCJB5UO5UBP6IIKXF X-Message-ID-Hash: BOAQZVMBH3337XENCJB5UO5UBP6IIKXF 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.88 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: 6C1FE940222 X-Spam-Score: -0.88 X-Migadu-Scanner: scn1.migadu.com X-TUID: GmLVYnALZvv/ The plan is to share code with a new database creation function that has a similar API to n_d_open_with_config. --- lib/open.cc | 50 +++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 8cede121..07498dec 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -113,6 +113,36 @@ DONE: return status; } +static notmuch_status_t +_pre_open(const char *config_path, + const char *profile, + GKeyFile **key_file, + const char **database_path, + 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 && *key_file) + *database_path = g_key_file_get_value (*key_file, "database", "path", NULL); + + if (*database_path == NULL) { + *message = strdup ("Error: Cannot open a database for a NULL path.\n"); + return NOTMUCH_STATUS_NULL_POINTER; + } + + if (*database_path[0] != '/') { + *message = strdup ("Error: Database path must be absolute.\n"); + return NOTMUCH_STATUS_PATH_ERROR; + } + return NOTMUCH_STATUS_SUCCESS; +} + notmuch_status_t notmuch_database_open_with_config (const char *database_path, notmuch_database_mode_t mode, @@ -132,26 +162,8 @@ notmuch_database_open_with_config (const char *database_path, GKeyFile *key_file = NULL; static int initialized = 0; - status = _load_key_file (config_path, profile, &key_file); - if (status) { - message = strdup ("Error: cannot load config file"); - goto DONE; - } - - if (! database_path && key_file) - database_path = g_key_file_get_value (key_file, "database", "path", NULL); - - if (database_path == NULL) { - message = strdup ("Error: Cannot open a database for a NULL path.\n"); - status = NOTMUCH_STATUS_NULL_POINTER; + if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message))) goto DONE; - } - - if (database_path[0] != '/') { - message = strdup ("Error: Database path must be absolute.\n"); - status = NOTMUCH_STATUS_PATH_ERROR; - goto DONE; - } if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { message = strdup ("Out of memory\n"); -- 2.29.2