aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-12-31 18:20:31 -0400
committerDavid Bremner <david@tethera.net>2021-03-20 07:39:12 -0300
commite823d05ae6dc920d4fc9abf774c3d2575d891d7b (patch)
treea66d028308be1a14a3b6f5fcae9feaa12cc3aede /lib
parent986056bdbcfea642a2d08f7ee257f7aaaed433b9 (diff)
lib: support splitting mail from database location.
Introduce a new configuration value for the mail root, and use it to locate mail messages in preference to the database.path (which previously implied the mail messages were also in this location. Initially only a subset of the CLI is tested in a split configuration. Further changes will be needed for the remainder of the CLI to work in split configurations.
Diffstat (limited to 'lib')
-rw-r--r--lib/config.cc11
-rw-r--r--lib/database.cc2
-rw-r--r--lib/message-file.c2
-rw-r--r--lib/message.cc2
-rw-r--r--lib/notmuch.h1
-rw-r--r--lib/open.cc5
6 files changed, 17 insertions, 6 deletions
diff --git a/lib/config.cc b/lib/config.cc
index 483a02ef..f2060e28 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -406,6 +406,8 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
switch (key) {
case NOTMUCH_CONFIG_DATABASE_PATH:
return "database.path";
+ case NOTMUCH_CONFIG_MAIL_ROOT:
+ return "database.mail_root";
case NOTMUCH_CONFIG_HOOK_DIR:
return "database.hook_dir";
case NOTMUCH_CONFIG_EXCLUDE_TAGS:
@@ -428,7 +430,7 @@ _notmuch_config_key_to_string (notmuch_config_key_t key)
}
static const char *
-_notmuch_config_default (void *ctx, notmuch_config_key_t key)
+_notmuch_config_default (notmuch_database_t *notmuch, notmuch_config_key_t key)
{
char *path;
@@ -436,11 +438,14 @@ _notmuch_config_default (void *ctx, notmuch_config_key_t key)
case NOTMUCH_CONFIG_DATABASE_PATH:
path = getenv ("MAILDIR");
if (path)
- path = talloc_strdup (ctx, path);
+ path = talloc_strdup (notmuch, path);
else
- path = talloc_asprintf (ctx, "%s/mail",
+ path = talloc_asprintf (notmuch, "%s/mail",
getenv ("HOME"));
return path;
+ case NOTMUCH_CONFIG_MAIL_ROOT:
+ /* by default, mail root is the same as database path */
+ return notmuch_database_get_path (notmuch);
case NOTMUCH_CONFIG_EXCLUDE_TAGS:
return "";
case NOTMUCH_CONFIG_NEW_TAGS:
diff --git a/lib/database.cc b/lib/database.cc
index 580b2d58..248d1dc2 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1350,7 +1350,7 @@ _notmuch_database_relative_path (notmuch_database_t *notmuch,
const char *db_path, *relative;
unsigned int db_path_len;
- db_path = notmuch_database_get_path (notmuch);
+ db_path = notmuch_config_get (notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
db_path_len = strlen (db_path);
relative = path;
diff --git a/lib/message-file.c b/lib/message-file.c
index 15b0bfad..9e9b387f 100644
--- a/lib/message-file.c
+++ b/lib/message-file.c
@@ -64,7 +64,7 @@ _notmuch_message_file_open_ctx (notmuch_database_t *notmuch,
if (unlikely (message == NULL))
return NULL;
- const char *prefix = notmuch_database_get_path (notmuch);
+ const char *prefix = notmuch_config_get (notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
if (prefix == NULL)
goto FAIL;
diff --git a/lib/message.cc b/lib/message.cc
index 73a7805f..0c2eeab5 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1102,7 +1102,7 @@ _notmuch_message_ensure_filename_list (notmuch_message_t *message)
*colon = '\0';
- db_path = notmuch_database_get_path (message->notmuch);
+ db_path = notmuch_config_get (message->notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
directory = _notmuch_database_get_directory_path (local,
message->notmuch,
diff --git a/lib/notmuch.h b/lib/notmuch.h
index b5688087..c9b01719 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2474,6 +2474,7 @@ notmuch_config_list_destroy (notmuch_config_list_t *config_list);
typedef enum _notmuch_config_key {
NOTMUCH_CONFIG_FIRST,
NOTMUCH_CONFIG_DATABASE_PATH = NOTMUCH_CONFIG_FIRST,
+ NOTMUCH_CONFIG_MAIL_ROOT,
NOTMUCH_CONFIG_HOOK_DIR,
NOTMUCH_CONFIG_EXCLUDE_TAGS,
NOTMUCH_CONFIG_NEW_TAGS,
diff --git a/lib/open.cc b/lib/open.cc
index 3bb3e103..8fc17caf 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -263,6 +263,11 @@ _choose_xapian_path (void *ctx, const char *database_path, const char **xapian_p
if (status)
goto DONE;
+ trial_path = talloc_asprintf (ctx, "%s/xapian", database_path);
+ status = _trial_open (trial_path, message_ptr);
+ if (status != NOTMUCH_STATUS_PATH_ERROR)
+ goto DONE;
+
notmuch_path = talloc_asprintf (ctx, "%s/.notmuch", database_path);
status = _db_dir_exists (notmuch_path, message_ptr);
if (status)