From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uCZLEmDhQGBzIwAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:32:16 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id qFcBDmDhQGCuWgAAB5/wlQ (envelope-from ) for ; Thu, 04 Mar 2021 13:32:16 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 9987D16A9A for ; Thu, 4 Mar 2021 14:32:15 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 440AE27BC2; Thu, 4 Mar 2021 08:31:50 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 8CA6A2705A for ; Thu, 4 Mar 2021 08:31:36 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 845905FA96; Thu, 4 Mar 2021 08:31:36 -0500 (EST) Received: (nullmailer pid 4053566 invoked by uid 1000); Thu, 04 Mar 2021 13:31:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 11/22] lib/open: factor out the second half of n_d_open_with_config Date: Thu, 4 Mar 2021 09:31:14 -0400 Message-Id: <20210304133125.4050229-12-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304133125.4050229-1-david@tethera.net> References: <20210304133125.4050229-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: SBA5QX2SAVYLJFSA5UJI6M3VD37VFBDW X-Message-ID-Hash: SBA5QX2SAVYLJFSA5UJI6M3VD37VFBDW 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=1614864735; 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=PCD4PGlVpJJ/woPjQkIO2K3yXRPIjzSTVZOP8muBiuY=; b=V+O1dkSm44UYJWB8g2n894q0pT+q4h1mt7gm4w1RYkY7Xda1T4cJ7PImOphCeiNvn7H4qz eNH1IAOJM9xtlK+Z7i+cV5UuF+uEHvjcv9k+xajexTLcQp5XnqDBlOIrT2jtS/sIySmxBJ O+iBk5Acf/MxVOiN8bAG0MijSxUn5wJNw3WRbxfHUpg2sNIxB6qeOjiQbl2KFewzgWmTV3 Liasa90nVZNZ4GZDjO2X6lN6dWNBCjtG0As7prtjraGLU84hncpyTff7RVRLXHYh+dHbpC cuXZWzlhonMTcUr8wshV67reLyk4UF2UgVaDo1FLQuuJS/iSE0uHnZFCN86tTA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614864735; a=rsa-sha256; cv=none; b=rGF/UFWmlCcy4GPJkplz1Jx1vaDvgIwCPXc8MeJM0G+qtIeevmXKzn6EtQeEGjoDXSponD +PcVYpzrGVe00pgBEUOIWl6t2rD67jKGm6VIRSUgYGNyKXKDelwmXL0VU56yQCgJ/7MfJl D6x/IV3s8sOdnDLsPGNCAqBVjM8NXe0wnEqy1LxgBBc1oHzquw6sIVyQGuBpHDZskYS8Jb u66YQ33Iur8Nm0X+ksVwE1JaY7/a2YmHJUDuZQljWGAmz9jHwNmrEQzSqhwVZL8O02FFHZ eyVLwxgFiNAa3e6Ixf8nydGTTS+/eFgjM/O2s2lAE7OYfWLdWFVZju5bUcgJOw== 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.80 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: 9987D16A9A X-Spam-Score: -0.80 X-Migadu-Scanner: scn1.migadu.com X-TUID: RsnnJYH5vYGK The idea is to allow reuse in n_d_create_with_config. This is primarily code movement, with some changes in error messages to reduce the number of input parameters. --- lib/open.cc | 115 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 68 insertions(+), 47 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 6a5c99dd..d052f95d 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -249,54 +249,18 @@ static void _init_libs () { } } -notmuch_status_t -notmuch_database_open_with_config (const char *database_path, - notmuch_database_mode_t mode, - const char *config_path, - const char *profile, - notmuch_database_t **database, - char **status_string) +static notmuch_status_t +_finish_open (notmuch_database_t *notmuch, + const char *profile, + notmuch_database_mode_t mode, + GKeyFile *key_file, + char **message_ptr) { notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; - void *local = talloc_new (NULL); - notmuch_database_t *notmuch = NULL; - char *notmuch_path, *incompat_features; + char *incompat_features; char *message = NULL; unsigned int version; - GKeyFile *key_file = NULL; - - _init_libs (); - - 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; - - _set_database_path (notmuch, database_path); - - status = _db_dir_exists (database_path, &message); - if (status) - goto DONE; - - if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { - message = strdup ("Out of memory\n"); - status = NOTMUCH_STATUS_OUT_OF_MEMORY; - goto DONE; - } - - status = _db_dir_exists (notmuch_path, &message); - if (status) - goto DONE; - - if (! (notmuch->xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { - message = strdup ("Out of memory\n"); - status = NOTMUCH_STATUS_OUT_OF_MEMORY; - goto DONE; - } + const char *database_path = notmuch_database_get_path (notmuch); try { std::string last_thread_id; @@ -319,7 +283,7 @@ notmuch_database_open_with_config (const char *database_path, "Error: Notmuch database at %s\n" " has a newer database format version (%u) than supported by this\n" " version of notmuch (%u).\n", - notmuch_path, version, NOTMUCH_DATABASE_VERSION)); + database_path, version, NOTMUCH_DATABASE_VERSION)); notmuch_database_destroy (notmuch); notmuch = NULL; status = NOTMUCH_STATUS_FILE_ERROR; @@ -329,7 +293,7 @@ notmuch_database_open_with_config (const char *database_path, /* Check features. */ incompat_features = NULL; notmuch->features = _notmuch_database_parse_features ( - local, notmuch->xapian_db->get_metadata ("features").c_str (), + notmuch, notmuch->xapian_db->get_metadata ("features").c_str (), version, mode == NOTMUCH_DATABASE_MODE_READ_WRITE ? 'w' : 'r', &incompat_features); if (incompat_features) { @@ -337,7 +301,7 @@ notmuch_database_open_with_config (const char *database_path, "Error: Notmuch database at %s\n" " requires features (%s)\n" " not supported by this version of notmuch.\n", - notmuch_path, incompat_features)); + database_path, incompat_features)); notmuch_database_destroy (notmuch); notmuch = NULL; status = NOTMUCH_STATUS_FILE_ERROR; @@ -415,6 +379,63 @@ notmuch_database_open_with_config (const char *database_path, notmuch = NULL; status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; } + DONE: + if (message_ptr) + *message_ptr = message; + return status; +} + +notmuch_status_t +notmuch_database_open_with_config (const char *database_path, + notmuch_database_mode_t mode, + const char *config_path, + const char *profile, + notmuch_database_t **database, + char **status_string) +{ + notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; + void *local = talloc_new (NULL); + notmuch_database_t *notmuch = NULL; + char *notmuch_path; + char *message = NULL; + struct stat st; + int err; + GKeyFile *key_file = NULL; + + _init_libs (); + + 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; + + _set_database_path (notmuch, database_path); + + status = _db_dir_exists (database_path, &message); + if (status) + goto DONE; + + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { + message = strdup ("Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + status = _db_dir_exists (notmuch_path, &message); + if (status) + goto DONE; + + if (! (notmuch->xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { + message = strdup ("Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + status = _finish_open (notmuch, profile, mode, key_file, &message); DONE: talloc_free (local); -- 2.30.1