From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id aEJqGMuIIGAYBwAA0tVLHw (envelope-from ) for ; Mon, 08 Feb 2021 00:41:47 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id WK4rFMuIIGDlbQAAbx9fmQ (envelope-from ) for ; Mon, 08 Feb 2021 00:41:47 +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 7C52F94029C for ; Mon, 8 Feb 2021 00:41:46 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 0B3C81FD68; Sun, 7 Feb 2021 19:41:25 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id BCE481FBA4 for ; Sun, 7 Feb 2021 19:41:19 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id B5F64606DB; Sun, 7 Feb 2021 19:41:19 -0500 (EST) Received: (nullmailer pid 1193274 invoked by uid 1000); Mon, 08 Feb 2021 00:41:15 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 11/23] lib/open: use _finish_open in n_d_create_with_config Date: Sun, 7 Feb 2021 20:40:57 -0400 Message-Id: <20210208004109.1192719-12-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208004109.1192719-1-david@tethera.net> References: <20210208004109.1192719-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: NOOIFP4XGKCCGB3TKDGMIJZ54S5IK25W X-Message-ID-Hash: NOOIFP4XGKCCGB3TKDGMIJZ54S5IK25W 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.05 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: 7C52F94029C X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: /z4Kq0G0L0te This avoids reading the configuration file twice. --- lib/open.cc | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 74fac37d..f4690763 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -459,14 +459,25 @@ notmuch_database_create_with_config (const char *database_path, notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; notmuch_database_t *notmuch = NULL; char *notmuch_path = NULL; + char *xapian_path = NULL; char *message = NULL; GKeyFile *key_file = NULL; struct stat st; int err; + void *local = talloc_new (NULL); + + notmuch = _alloc_notmuch (); + if (! notmuch) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } if ((status = _choose_database_path (config_path, profile, &key_file, &database_path, &message))) goto DONE; + notmuch->path = talloc_strdup (notmuch, database_path); + strip_trailing (notmuch->path, '/'); + err = stat (database_path, &st); if (err) { IGNORE_RESULT (asprintf (&message, "Error: Cannot create database at %s: %s.\n", @@ -483,12 +494,14 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - notmuch_path = talloc_asprintf (NULL, "%s/%s", database_path, ".notmuch"); + notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"); err = mkdir (notmuch_path, 0755); if (err) { if (errno == EEXIST) { status = NOTMUCH_STATUS_DATABASE_EXISTS; + talloc_free (notmuch); + notmuch = NULL; } else { IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n", notmuch_path, strerror (errno))); @@ -497,12 +510,16 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - /* XXX this reads the config file twice, which is a bit wasteful */ - status = notmuch_database_open_with_config (database_path, - NOTMUCH_DATABASE_MODE_READ_WRITE, - config_path, - profile, - ¬much, &message); + if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + status = _finish_open (notmuch, + profile, + NOTMUCH_DATABASE_MODE_READ_WRITE, + key_file, + &message); if (status) goto DONE; @@ -519,8 +536,7 @@ notmuch_database_create_with_config (const char *database_path, } DONE: - if (notmuch_path) - talloc_free (notmuch_path); + talloc_free(local); if (message) { if (status_string) -- 2.30.0