unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH 03/22] lib: save path of xapian database in notmuch struct.
Date: Sun, 14 Mar 2021 11:01:58 -0300	[thread overview]
Message-ID: <20210314140217.183425-4-david@tethera.net> (raw)
In-Reply-To: <20210314140217.183425-1-david@tethera.net>

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

  parent reply	other threads:[~2021-03-14 14:04 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-14 14:01 v4 flexible path location David Bremner
2021-03-14 14:01 ` [PATCH 01/22] test/setup: add check for config exists, but no database David Bremner
2021-03-14 14:01 ` [PATCH 02/22] lib: publish API for notmuch_database_reopen David Bremner
2021-03-14 14:01 ` David Bremner [this message]
2021-03-14 14:01 ` [PATCH 04/22] lib: support reopening databases for write access David Bremner
2021-03-18 11:11   ` David Bremner
2021-03-14 14:02 ` [PATCH 05/22] CLI/show: complete conversion to new configuration framework David Bremner
2021-03-14 14:02 ` [PATCH 06/22] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
2021-03-14 14:02 ` [PATCH 07/22] lib/open: allocate notmuch_t struct early David Bremner
2021-03-14 14:02 ` [PATCH 08/22] lib: remove "path" from notmuch struct David Bremner
2021-03-14 14:02 ` [PATCH 09/22] lib/open: factor out library initialization David Bremner
2021-03-14 14:02 ` [PATCH 10/22] lib/open: reuse directory checks from n_d_c_with_config David Bremner
2021-03-14 14:02 ` [PATCH 11/22] lib/open: factor out the second half of n_d_open_with_config David Bremner
2021-03-14 14:02 ` [PATCH 12/22] lib/open: use _finish_open in n_d_create_with_config David Bremner
2021-03-14 14:02 ` [PATCH 13/22] lib/open: Use check for existing database by trial opening David Bremner
2021-03-14 14:02 ` [PATCH 14/22] lib: support splitting mail from database location David Bremner
2021-03-14 14:02 ` [PATCH 15/22] lib/open: check for split configuration when creating database David Bremner
2021-03-14 14:02 ` [PATCH 16/22] CLI/new: support split database and mail location David Bremner
2021-03-14 14:02 ` [PATCH 17/22] lib/open: support XDG_DATA_HOME as a fallback database location David Bremner
2021-03-14 14:02 ` [PATCH 18/22] CLI/insert: support split database and mail root David Bremner
2021-03-14 14:02 ` [PATCH 19/22] lib/compact: enable split config David Bremner
2021-03-14 14:02 ` [PATCH 20/22] lib/open: fix hook directory calculation in split configuration David Bremner
2021-03-14 14:02 ` [PATCH 21/22] lib/config: add configuration variable for backup directory David Bremner
2021-03-14 14:02 ` [PATCH 22/22] CLI/new: use " David Bremner
2021-03-20 11:10 ` v4 flexible path location David Bremner
2021-03-24 11:08 ` David Bremner
  -- strict thread matches above, loose matches on Subject: below --
2021-03-07 17:27 v3 support flexible database location David Bremner
2021-03-07 17:27 ` [PATCH 03/22] lib: save path of xapian database in notmuch struct David Bremner
2021-03-04 13:31 v2 support flexible database location David Bremner
2021-03-04 13:31 ` [PATCH 03/22] lib: save path of xapian database in notmuch struct David Bremner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://notmuchmail.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210314140217.183425-4-david@tethera.net \
    --to=david@tethera.net \
    --cc=notmuch@notmuchmail.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).