From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id lebWH9sXTmAVHgAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:04:11 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cEoRG9sXTmCgQgAAB5/wlQ (envelope-from ) for ; Sun, 14 Mar 2021 14:04:11 +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)) (No client certificate requested) by aspmx2.migadu.com (Postfix) with ESMTPS id EEABB10DAE for ; Sun, 14 Mar 2021 15:04:10 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id A8AB527D74; Sun, 14 Mar 2021 10:02:57 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id D34D627C3B for ; Sun, 14 Mar 2021 10:02:35 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id CB0775FA96; Sun, 14 Mar 2021 10:02:35 -0400 (EDT) Received: (nullmailer pid 183635 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 03/22] lib: save path of xapian database in notmuch struct. Date: Sun, 14 Mar 2021 11:01:58 -0300 Message-Id: <20210314140217.183425-4-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210314140217.183425-1-david@tethera.net> References: <20210314140217.183425-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: C5GBSK5PNKSOHRT3ZSGCNLPJJE6BRSNW X-Message-ID-Hash: C5GBSK5PNKSOHRT3ZSGCNLPJJE6BRSNW 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=1615730651; 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=j1nBhT3J9l0vdpsjClu0KNZkPVk1yyWNF0abysCiGMg=; b=ITm5Kx+X1AFUhWSAqxwn5FFRAqOpk3edp5JPQJx874l7Pkg3vtxo3sU93tJWWgzPiKK/0U tc9cBGrFTxBnCFpP0YHDLjMuQR7575Wyqw1EufUMIuotRP+frt4Xu+DdWAVWsEGbNsUo/J 30OUoJjqOcIIcCp8OMNFy7dPhXxg3k43YnU2847QIFmR9IibDFv3irFaGkougN06pRxWw7 w6QpgY5AZduGgqhE78fsPXPUrkuFYvXNX+dG9XBR0eyalUPcsXkInB4EROH3zWpwPjcrYR ix7ka1/MOeCqo/5yKCY7qDnI7M3wyN/Cpl5cEWCFlZMVjV53d152fpqVinNGbg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730651; a=rsa-sha256; cv=none; b=MmT5Lv9O1Ut8FWJbYige/+sX0XwwIvqqEZwFxlIso212HiBYPJUldltNbgzQr8CzgMngu2 WHNofy+0uZm3ILyjq2jeYPHQP/6bIVqrpYsNRQC1dRlEkWZzX2Y+O3slkb/IwfNyyOQTCB t6Rguo92XsW+4V6mZUB0jEjQkCa10pVT9g5tQUZ2qMFfj8dO4gIOMKG5SRhZyrT3QcNClw B8sFWZeX92rzMLc7tdXrEyTdQJsyDvGkcBGe8so5u/PD1tjVwcsrdqy6aXNAFY8uvgqkdE 5EJVAtm1kaZOmKbbNNcB9fwDwWFreVLVnAkrmuLlh/rlEQQtJRLvHrAUgp3kPg== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx2.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: -1.00 Authentication-Results: aspmx2.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx2.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: EEABB10DAE X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: klt5dFd1oo6x This will allow re-opening in a different mode (read/write vs. read-only) with current Xapian API. It will also prove useful when updating the compact functions to support more flexible database location. --- lib/database-private.h | 4 ++++ lib/open.cc | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/database-private.h b/lib/database-private.h index d83cf0d0..d936b216 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -189,8 +189,12 @@ operator& (notmuch_field_flag_t a, notmuch_field_flag_t b) struct _notmuch_database { bool exception_reported; + /* Path to database parent directory and or/mail root */ char *path; + /* Path to actual database */ + const char *xapian_path; + int atomic_nesting; /* true if changes have been made in this atomic section */ bool atomic_dirty; diff --git a/lib/open.cc b/lib/open.cc index 0c965d0d..12d3613f 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -199,7 +199,7 @@ notmuch_database_open_with_config (const char *database_path, notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; void *local = talloc_new (NULL); notmuch_database_t *notmuch = NULL; - char *notmuch_path, *xapian_path, *incompat_features; + char *notmuch_path, *incompat_features; char *message = NULL; struct stat st; int err; @@ -225,12 +225,6 @@ notmuch_database_open_with_config (const char *database_path, goto DONE; } - if (! (xapian_path = talloc_asprintf (local, "%s/%s", notmuch_path, "xapian"))) { - message = strdup ("Out of memory\n"); - status = NOTMUCH_STATUS_OUT_OF_MEMORY; - goto DONE; - } - /* Initialize the GLib type system and threads */ #if ! GLIB_CHECK_VERSION (2, 35, 1) g_type_init (); @@ -252,16 +246,23 @@ notmuch_database_open_with_config (const char *database_path, notmuch->writable_xapian_db = NULL; notmuch->atomic_nesting = 0; notmuch->view = 1; + + if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) { + message = strdup ("Out of memory\n"); + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + try { std::string last_thread_id; std::string last_mod; if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) { - notmuch->writable_xapian_db = new Xapian::WritableDatabase (xapian_path, + notmuch->writable_xapian_db = new Xapian::WritableDatabase (notmuch->xapian_path, DB_ACTION); notmuch->xapian_db = notmuch->writable_xapian_db; } else { - notmuch->xapian_db = new Xapian::Database (xapian_path); + notmuch->xapian_db = new Xapian::Database (notmuch->xapian_path); } /* Check version. As of database version 3, we represent -- 2.30.1