unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* v3 support flexible database location
@ 2021-03-07 17:27 David Bremner
  2021-03-07 17:27 ` [PATCH 01/22] test/setup: add check for config exists, but no database David Bremner
                   ` (21 more replies)
  0 siblings, 22 replies; 25+ messages in thread
From: David Bremner @ 2021-03-07 17:27 UTC (permalink / raw)
  To: notmuch

This series obsoletes [0], although it does not contain any functional
changes since that series.

It is rebased against memory leak [1] and style [2] fixes. It also
contains several style fixes of its own, which hopefully makes it less
time consuming to review.

[0]: id:20210304133125.4050229-1-david@tethera.net
[1]: id:20210306134934.491249-1-david@tethera.net
[2]: id:20210307171658.1084026-1-david@tethera.net

diff --git a/lib/config.cc b/lib/config.cc
index 4541fe95..79d33850 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -503,7 +503,7 @@ void
 _notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val)
 {
     if (notmuch->config == NULL)
-       notmuch->config = _notmuch_string_map_create (notmuch);
+	notmuch->config = _notmuch_string_map_create (notmuch);
 
     _notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val);
 }
diff --git a/lib/database.cc b/lib/database.cc
index 707854b5..491ede5e 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -610,7 +610,7 @@ notmuch_database_compact_db (notmuch_database_t *notmuch,
 {
     void *local;
     const char *xapian_path, *compact_xapian_path;
-    const char* path;
+    const char *path;
     notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
     struct stat statbuf;
     bool keep_backup;
diff --git a/lib/open.cc b/lib/open.cc
index d62fc6ca..5ff7c4b7 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -91,7 +91,7 @@ _choose_dir (notmuch_database_t *notmuch,
 
     parent = _xdg_dir (notmuch, xdg_var, xdg_subdir, profile);
     if (! parent)
-	return  NOTMUCH_STATUS_PATH_ERROR;
+	return NOTMUCH_STATUS_PATH_ERROR;
 
     dir = talloc_asprintf (notmuch, "%s/%s", parent, subdir);
 
@@ -99,7 +99,7 @@ _choose_dir (notmuch_database_t *notmuch,
     if (err) {
 	if (errno == ENOENT) {
 	    char *notmuch_path = dirname (talloc_strdup (notmuch, notmuch->xapian_path));
-            dir = talloc_asprintf (notmuch, "%s/%s", notmuch_path, subdir);
+	    dir = talloc_asprintf (notmuch, "%s/%s", notmuch_path, subdir);
 	} else {
 	    IGNORE_RESULT (asprintf (message, "Error: Cannot stat %s: %s.\n",
 				     dir, strerror (errno)));
@@ -199,7 +199,7 @@ _choose_database_path (void *ctx,
     }
 
     if (! *database_path) {
-       *database_path = getenv ("NOTMUCH_DATABASE");
+	*database_path = getenv ("NOTMUCH_DATABASE");
     }
 
     if (! *database_path && *key_file) {
@@ -227,10 +227,13 @@ _choose_database_path (void *ctx,
     return NOTMUCH_STATUS_SUCCESS;
 }
 
-notmuch_database_t * _alloc_notmuch() {
-    notmuch_database_t * notmuch;
+notmuch_database_t *
+_alloc_notmuch ()
+{
+    notmuch_database_t *notmuch;
+
     notmuch = talloc_zero (NULL, notmuch_database_t);
-    if (!notmuch)
+    if (! notmuch)
 	return NULL;
 
     notmuch->exception_reported = false;
@@ -245,7 +248,7 @@ static notmuch_status_t
 _trial_open (const char *xapian_path, char **message_ptr)
 {
     try {
-	Xapian::Database db(xapian_path);
+	Xapian::Database db (xapian_path);
     } catch (const Xapian::DatabaseOpeningError &error) {
 	IGNORE_RESULT (asprintf (message_ptr,
 				 "Cannot open Xapian database at %s: %s\n",
@@ -261,8 +264,10 @@ _trial_open (const char *xapian_path, char **message_ptr)
     return NOTMUCH_STATUS_SUCCESS;
 }
 
+
 notmuch_status_t
-_notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **xapian_path, char **message_ptr){
+_notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **xapian_path, char **message_ptr)
+{
     notmuch_status_t status;
     const char *trial_path, *notmuch_path;
 
@@ -283,7 +288,7 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **
     trial_path = talloc_asprintf (ctx, "%s/xapian", notmuch_path);
     status = _trial_open (trial_path, message_ptr);
 
- DONE:
+  DONE:
     if (status == NOTMUCH_STATUS_SUCCESS)
 	*xapian_path = trial_path;
     return status;
@@ -291,15 +296,18 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **
 
 static void
 _set_database_path (notmuch_database_t *notmuch,
-          const char *database_path) {
-    char *path=talloc_strdup (notmuch, database_path);
+		    const char *database_path)
+{
+    char *path = talloc_strdup (notmuch, database_path);
 
     strip_trailing (path, '/');
 
     _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
 }
 
-static void _init_libs () {
+static void
+_init_libs ()
+{
 
     static int initialized = 0;
 
@@ -437,8 +445,8 @@ _finish_open (notmuch_database_t *notmuch,
 			      ".local/share",
 			      "backups",
 			      &message);
-        if (status)
-            goto DONE;
+	if (status)
+	    goto DONE;
 	status = _notmuch_config_load_defaults (notmuch);
 	if (status)
 	    goto DONE;
@@ -458,7 +466,7 @@ _finish_open (notmuch_database_t *notmuch,
 	notmuch = NULL;
 	status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
     }
- DONE:
+  DONE:
     if (message_ptr)
 	*message_ptr = message;
     return status;
@@ -482,7 +490,7 @@ notmuch_database_open_with_config (const char *database_path,
     _init_libs ();
 
     notmuch = _alloc_notmuch ();
-    if (!notmuch) {
+    if (! notmuch) {
 	status = NOTMUCH_STATUS_OUT_OF_MEMORY;
 	goto DONE;
     }
@@ -588,14 +596,14 @@ notmuch_database_create_with_config (const char *database_path,
 
     _set_database_path (notmuch, database_path);
 
-    if (key_file && !split) {
+    if (key_file && ! split) {
 	char *mail_root = canonicalize_file_name (
 	    g_key_file_get_value (key_file, "database", "mail_root", NULL));
 	char *db_path = canonicalize_file_name (database_path);
 
 	split = (mail_root && (0 != strcmp (mail_root, db_path)));
 
-	free(mail_root);
+	free (mail_root);
 	free (db_path);
     }
 
@@ -679,6 +687,7 @@ notmuch_database_reopen (notmuch_database_t *notmuch,
 			 notmuch_database_mode_t new_mode)
 {
     notmuch_database_mode_t cur_mode = _notmuch_database_mode (notmuch);
+
     if (notmuch->xapian_db == NULL) {
 	_notmuch_database_log (notmuch, "Cannot reopen closed or nonexistent database\n");
 	return NOTMUCH_STATUS_ILLEGAL_ARGUMENT;
@@ -708,7 +717,7 @@ notmuch_database_reopen (notmuch_database_t *notmuch,
     } catch (const Xapian::Error &error) {
 	if (! notmuch->exception_reported) {
 	    _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",
-					   error.get_msg ().c_str ());
+				   error.get_msg ().c_str ());
 	    notmuch->exception_reported = true;
 	}
 	return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
diff --git a/notmuch-new.c b/notmuch-new.c
index 834c36fb..9a89761d 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -1056,7 +1056,7 @@ _maybe_upgrade (notmuch_database_t *notmuch, add_files_state_t *state)
 
 	err = mkdir (backup_dir, 0755);
 	if (err && errno != EEXIST) {
-	    fprintf(stderr, "Failed to create %s: %s\n", backup_dir, strerror(errno));
+	    fprintf (stderr, "Failed to create %s: %s\n", backup_dir, strerror (errno));
 	    return EXIT_FAILURE;
 	}
 

^ permalink raw reply related	[flat|nested] 25+ messages in thread
* v4 flexible path location
@ 2021-03-14 14:01 David Bremner
  2021-03-14 14:02 ` [PATCH 06/22] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
  0 siblings, 1 reply; 25+ messages in thread
From: David Bremner @ 2021-03-14 14:01 UTC (permalink / raw)
  To: notmuch

Since v3 [1]

- rebase against the uncrustified version (unfortunately this makes an
  interdiff too noisy to be helpful).
- improve (?) the documentation of database.mail_root in notmuch-config(1).
- tweak commit messages
- move the call to _init_libs from [10/22] to [9/22]

I'm going to mark this version as ready to apply, so object now, or
grumble later.

[1]: id:20210307172734.1091264-1-david@tethera.net

[PATCH 09/22] lib/open: factor out library initialization
[PATCH 10/22] lib/open: reuse directory checks from n_d_c_with_config

^ permalink raw reply	[flat|nested] 25+ messages in thread
* v2 support flexible database location
@ 2021-03-04 13:31 David Bremner
  2021-03-04 13:31 ` [PATCH 06/22] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
  0 siblings, 1 reply; 25+ messages in thread
From: David Bremner @ 2021-03-04 13:31 UTC (permalink / raw)
  To: notmuch

This obsoletes [1]. It is mainly a rebase against master, but also
adds one test (see below).  I have been running this code in
production for a few weeks now, although without using any of the
fancy new features.

[1]: id:20210208004109.1192719-1-david@tethera.net

diff --git a/test/T040-setup.sh b/test/T040-setup.sh
index 1223ebf7..5eb281d7 100755
--- a/test/T040-setup.sh
+++ b/test/T040-setup.sh
@@ -34,4 +34,20 @@ built_with.compact=something
 built_with.field_processor=something
 built_with.retry_lock=something"
 
+test_begin_subtest "notmuch with a config but without a database suggests notmuch new"
+notmuch 2>&1 | notmuch_dir_sanitize > OUTPUT
+cat <<EOF > EXPECTED
+Notmuch is configured, but there's not yet a database at
+
+       MAIL_DIR/.notmuch
+
+You probably want to run "notmuch new" now to create that database.
+
+Note that the first run of "notmuch new" can take a very long time
+and that the resulting database will use roughly the same amount of
+storage space as the email being indexed.
+
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+

^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2021-03-14 14:04 UTC | newest]

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

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).