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 2E6jNdscA2BFIAAA0tVLHw (envelope-from ) for ; Sat, 16 Jan 2021 17:05:31 +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 IDtpMdscA2ALQAAA1q6Kng (envelope-from ) for ; Sat, 16 Jan 2021 17:05:31 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 923929404D0 for ; Sat, 16 Jan 2021 17:05:31 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 2832C2BF70; Sat, 16 Jan 2021 12:04:47 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id DE73E2A12B for ; Sat, 16 Jan 2021 12:04:27 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id D58D25FF47; Sat, 16 Jan 2021 12:04:27 -0500 (EST) Received: (nullmailer pid 842435 invoked by uid 1000); Sat, 16 Jan 2021 17:04:16 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 28/38] lib/open: factor out first part of open Date: Sat, 16 Jan 2021 13:03:56 -0400 Message-Id: <20210116170406.842014-29-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210116170406.842014-1-david@tethera.net> References: <20210116170406.842014-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: DAI4BGQOGU23U2UZQV7AK54UQJQ7TU55 X-Message-ID-Hash: DAI4BGQOGU23U2UZQV7AK54UQJQ7TU55 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: -1.08 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: 923929404D0 X-Spam-Score: -1.08 X-Migadu-Scanner: scn0.migadu.com X-TUID: BcXVKoBagI6K 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