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 8D41Ho1V8l8KBwAA0tVLHw (envelope-from ) for ; Sun, 03 Jan 2021 23:38:53 +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 6Fv8GY1V8l8MUgAAB5/wlQ (envelope-from ) for ; Sun, 03 Jan 2021 23:38:53 +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 3194294038E for ; Sun, 3 Jan 2021 23:38:53 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 6A74D29E9E; Sun, 3 Jan 2021 18:37:21 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 25BE329D97 for ; Sun, 3 Jan 2021 18:36:29 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 206D05FF47; Sun, 3 Jan 2021 18:36:29 -0500 (EST) Received: (nullmailer pid 126244 invoked by uid 1000); Sun, 03 Jan 2021 23:35:56 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 25/36] lib: split notmuch_database_compact Date: Sun, 3 Jan 2021 19:35:36 -0400 Message-Id: <20210103233547.122707-26-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: FCJHY6PUYWNVFZBPHGRA6SDTKN4IOUBG X-Message-ID-Hash: FCJHY6PUYWNVFZBPHGRA6SDTKN4IOUBG 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: 3194294038E X-Spam-Score: -0.88 X-Migadu-Scanner: scn1.migadu.com X-TUID: /SIbhejgJr83 The "back end" function takes an open notmuch database, which should know its own path (i.e. the path needs to be cached in the configuration data). --- lib/database.cc | 42 +++++++++++++++++++++++++++++++++--------- lib/notmuch.h | 12 ++++++++++++ 2 files changed, 45 insertions(+), 9 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index 0f4e2ff9..650359f4 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -705,27 +705,51 @@ notmuch_database_compact (const char *path, notmuch_compact_status_cb_t status_cb, void *closure) { - void *local; - char *notmuch_path, *xapian_path, *compact_xapian_path; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; notmuch_database_t *notmuch = NULL; - struct stat statbuf; - bool keep_backup; char *message = NULL; - local = talloc_new (NULL); - if (! local) - return NOTMUCH_STATUS_OUT_OF_MEMORY; - ret = notmuch_database_open_verbose (path, NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much, &message); if (ret) { if (status_cb) status_cb (message, closure); - goto DONE; + return ret; } + _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path); + + return notmuch_database_compact_db (notmuch, + backup_path, + status_cb, + closure); +} + +notmuch_status_t +notmuch_database_compact_db (notmuch_database_t *notmuch, + const char *backup_path, + notmuch_compact_status_cb_t status_cb, + void *closure) { + void *local; + char *notmuch_path, *xapian_path, *compact_xapian_path; + const char* path; + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; + struct stat statbuf; + bool keep_backup; + + ret = _notmuch_database_ensure_writable (notmuch); + if (ret) + return ret; + + path = notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH); + if (! path) + return NOTMUCH_STATUS_PATH_ERROR; + + local = talloc_new (NULL); + if (! local) + return NOTMUCH_STATUS_OUT_OF_MEMORY; + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) { ret = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; diff --git a/lib/notmuch.h b/lib/notmuch.h index 70fe717d..377831ea 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -497,6 +497,18 @@ notmuch_database_compact (const char *path, notmuch_compact_status_cb_t status_cb, void *closure); +/** + * Like notmuch_database_compact, but take an open database as a + * parameter. + * + * @since libnnotmuch 5.4 (notmuch 0.32) + */ +notmuch_status_t +notmuch_database_compact_db (notmuch_database_t *database, + const char *backup_path, + notmuch_compact_status_cb_t status_cb, + void *closure); + /** * Destroy the notmuch database, closing it if necessary and freeing * all associated resources. -- 2.29.2