* v1 flexible database location
@ 2021-01-05 2:23 David Bremner
2021-01-05 2:23 ` [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch
This adds support for split mail / database location, and fallback to
XDG consistent database location. There are quite a few code paths to
test, and several more tests are most likely needed.
This applies on top of the series at id:20210103233547.122707-1-david@tethera.net.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable
2021-01-05 2:23 v1 flexible database location David Bremner
@ 2021-01-05 2:23 ` David Bremner
2021-01-05 2:23 ` [PATCH 2/5] support splitting mail from database location David Bremner
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
The additional code is trivial, but making sure we get the priority of
various options correct takes a few tests.
---
lib/open.cc | 4 +++
test/T590-libconfig.sh | 67 +++++++++++++++++++++++++++++++++++++++++-
2 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/lib/open.cc b/lib/open.cc
index 92661271..acc9f7a4 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -162,6 +162,10 @@ notmuch_database_open_with_config (const char *database_path,
GKeyFile *key_file = NULL;
static int initialized = 0;
+ if (! database_path) {
+ database_path = getenv ("NOTMUCH_DATABASE");
+ }
+
if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
goto DONE;
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 97f8fdc7..7f187d36 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -27,7 +27,7 @@ int main (int argc, char** argv)
&db,
&msg);
if (stat != NOTMUCH_STATUS_SUCCESS) {
- fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : "");
+ fprintf (stderr, "error opening database\n%s\n%s\n", notmuch_status_to_string (stat), msg ? msg : "");
exit (1);
}
EOF
@@ -473,4 +473,69 @@ EOF
test_expect_equal_file EXPECTED OUTPUT
restore_database
+test_begin_subtest "no config, fail to open database"
+old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
+unset NOTMUCH_CONFIG
+cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
+{
+ printf("NOT RUN");
+}
+EOF
+NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
+cat <<'EOF' >EXPECTED
+== stdout ==
+== stderr ==
+error opening database
+Erroneous NULL pointer
+Error: Cannot open a database for a NULL path.
+
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "open database from NOTMUCH_DATABASE"
+old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG}
+unset NOTMUCH_CONFIG
+export NOTMUCH_DATABASE=${MAIL_DIR}
+cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
+{
+ EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
+ printf("test.key1 = %s\n", val);
+ EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
+ printf("test.key2 = %s\n", val);
+}
+EOF
+NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
+unset NOTMUCH_DATABASE
+cat <<'EOF' >EXPECTED
+== stdout ==
+test.key1 = testvalue1
+test.key2 = testvalue2
+== stderr ==
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "NOTMUCH_DATABASE overrides config"
+old_path=$(notmuch config get database.path)
+notmuch config set database.path /nonexistent
+export NOTMUCH_DATABASE=${MAIL_DIR}
+cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL%
+{
+ EXPECT0(notmuch_database_get_config (db, "test.key1", &val));
+ printf("test.key1 = %s\n", val);
+ EXPECT0(notmuch_database_get_config (db, "test.key2", &val));
+ printf("test.key2 = %s\n", val);
+}
+EOF
+NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG}
+unset NOTMUCH_DATABASE
+cat <<'EOF' >EXPECTED
+== stdout ==
+test.key1 = testvalue1
+test.key2 = testvalue2
+== stderr ==
+EOF
+notmuch config set database.path "${old_path}"
+test_expect_equal_file EXPECTED OUTPUT
+
+
test_done
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] support splitting mail from database location.
2021-01-05 2:23 v1 flexible database location David Bremner
2021-01-05 2:23 ` [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
@ 2021-01-05 2:23 ` David Bremner
2021-01-07 11:50 ` [PATCH] fixup! " David Bremner
2021-01-05 2:23 ` [PATCH 3/5] lib/open: move path calculations after notmuch object creation David Bremner
` (2 subsequent siblings)
4 siblings, 1 reply; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
Introduce a new configuration value for the mail root, and use it in
preference to the database.path (which previously implied the mail was
also in this location.
---
doc/man1/notmuch-config.rst | 14 +++++++++---
lib/config.cc | 11 +++++++---
lib/database.cc | 2 +-
lib/message-file.c | 2 +-
lib/message.cc | 2 +-
lib/notmuch.h | 1 +
lib/open.cc | 2 +-
test/T055-path-config.sh | 43 +++++++++++++++++++++++++++++++++++++
test/T590-libconfig.sh | 1 +
9 files changed, 68 insertions(+), 10 deletions(-)
create mode 100755 test/T055-path-config.sh
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 769f336a..fb2b8671 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -47,12 +47,20 @@ programmatically as described in the SYNOPSIS above.
The available configuration items are described below.
**database.path**
+ Notmuch will store its database within a
+ sub-directory of the path configured here named ``.notmuch``.
+
+ Default: ``$MAILDIR`` variable if set, otherwise ``$HOME/mail``.
+
+**database.mail_root**
The top-level directory where your mail currently exists and to
where mail will be delivered in the future. Files should be
- individual email messages. Notmuch will store its database within
- a sub-directory of the path configured here named ``.notmuch``.
+ individual email messages.
- Default: ``$MAILDIR`` variable if set, otherwise ``$HOME/mail``.
+ History: this configuration value was introduced in notmuch 0.32.
+
+ Default: For compatibility with older configurations, the value of
+ database.path is used if database.mail\_root is unset..
**user.name**
Your full name.
diff --git a/lib/config.cc b/lib/config.cc
index 7a1494be..a8aa151b 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -388,6 +388,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_EXCLUDE_TAGS:
return "search.exclude_tags";
case NOTMUCH_CONFIG_NEW_TAGS:
@@ -408,18 +410,21 @@ _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;
switch (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 f96ba7c0..c646fee2 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1367,7 +1367,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 311bd478..a23493f1 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 fca99082..e596456c 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -1097,7 +1097,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 e51b738d..f659d1a4 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -2461,6 +2461,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_EXCLUDE_TAGS,
NOTMUCH_CONFIG_NEW_TAGS,
NOTMUCH_CONFIG_NEW_IGNORE,
diff --git a/lib/open.cc b/lib/open.cc
index acc9f7a4..12cbbbd0 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -203,8 +203,8 @@ notmuch_database_open_with_config (const char *database_path,
notmuch = talloc_zero (NULL, notmuch_database_t);
notmuch->exception_reported = false;
notmuch->status_string = NULL;
- notmuch->path = talloc_strdup (notmuch, database_path);
+ notmuch->path = talloc_strdup (notmuch, database_path);
strip_trailing (notmuch->path, '/');
notmuch->writable_xapian_db = NULL;
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
new file mode 100755
index 00000000..190b3686
--- /dev/null
+++ b/test/T055-path-config.sh
@@ -0,0 +1,43 @@
+#!/usr/bin/env bash
+test_description='Configuration of mail-root and database path'
+. $(dirname "$0")/test-lib.sh || exit 1
+
+add_email_corpus
+
+test_begin_subtest "database is mail/.notmuch/xapian"
+output=$(notmuch count '*')
+test_expect_equal $output '52'
+
+backup_database
+test_begin_subtest "split (with prefix)"
+notmuch config set database.path `pwd`/database
+notmuch config set database.mail_root `pwd`/mail
+mkdir database
+mv mail/.notmuch database
+output=$(notmuch count '*')
+test_expect_equal "$output" '52'
+restore_database
+
+backup_database
+test_begin_subtest "split (read-write)"
+notmuch config set database.path `pwd`/database
+notmuch config set database.mail_root `pwd`/mail
+mkdir database
+mv mail/.notmuch database
+tag="tag${RANDOM}"
+notmuch tag +$tag '*'
+output=$(notmuch count tag:$tag)
+test_expect_equal "$output" '52'
+restore_database
+
+backup_database
+test_begin_subtest "create database in split configuration"
+notmuch config set database.path `pwd`/database
+notmuch config set database.mail_root `pwd`/mail
+rm -r mail/.notmuch/xapian
+notmuch new
+output=$(notmuch count '*')
+test_expect_equal "$output" '52'
+restore_database
+
+test_done
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 7f187d36..b03ee0c6 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -333,6 +333,7 @@ EOF
cat <<'EOF' >EXPECTED
== stdout ==
MAIL_DIR
+MAIL_DIR
inbox;unread
NULL
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] lib/open: move path calculations after notmuch object creation
2021-01-05 2:23 v1 flexible database location David Bremner
2021-01-05 2:23 ` [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
2021-01-05 2:23 ` [PATCH 2/5] support splitting mail from database location David Bremner
@ 2021-01-05 2:23 ` David Bremner
2021-01-05 2:23 ` [PATCH 4/5] lib/open: open xapian database without .notmuch prefix David Bremner
2021-01-05 2:23 ` [PATCH 5/5] lib/open: support XDG_DATA_HOME as a fallback database location David Bremner
4 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
This is just code movement. A future commit will need the notmuch
object to exist for the path manipulation.
---
lib/open.cc | 41 +++++++++++++++++++++--------------------
1 file changed, 21 insertions(+), 20 deletions(-)
diff --git a/lib/open.cc b/lib/open.cc
index 12cbbbd0..ede367af 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -169,26 +169,6 @@ notmuch_database_open_with_config (const char *database_path,
if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
goto DONE;
- if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
- message = strdup ("Out of memory\n");
- status = NOTMUCH_STATUS_OUT_OF_MEMORY;
- goto DONE;
- }
-
- err = stat (notmuch_path, &st);
- if (err) {
- IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
- notmuch_path, strerror (errno)));
- status = NOTMUCH_STATUS_FILE_ERROR;
- 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 ();
@@ -210,6 +190,27 @@ notmuch_database_open_with_config (const char *database_path,
notmuch->writable_xapian_db = NULL;
notmuch->atomic_nesting = 0;
notmuch->view = 1;
+
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
+ message = strdup ("Out of memory\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ goto DONE;
+ }
+
+ err = stat (notmuch_path, &st);
+ if (err) {
+ IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
+ notmuch_path, strerror (errno)));
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ 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;
+ }
+
try {
std::string last_thread_id;
std::string last_mod;
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] lib/open: open xapian database without .notmuch prefix.
2021-01-05 2:23 v1 flexible database location David Bremner
` (2 preceding siblings ...)
2021-01-05 2:23 ` [PATCH 3/5] lib/open: move path calculations after notmuch object creation David Bremner
@ 2021-01-05 2:23 ` David Bremner
2021-01-05 2:23 ` [PATCH 5/5] lib/open: support XDG_DATA_HOME as a fallback database location David Bremner
4 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
In a split configuration, it does not make sense to have the extra
.notmuch/ directory. Leave the xapian/ level of the path to allow the
use of the top level e.g. as a place to store backups as is currently
done by upgrade code in notmuch-new.
---
lib/open.cc | 59 ++++++++++++++++++++++++++++------------
test/T055-path-config.sh | 9 ++++++
2 files changed, 50 insertions(+), 18 deletions(-)
diff --git a/lib/open.cc b/lib/open.cc
index ede367af..91b24e38 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -8,6 +8,8 @@
#define DB_ACTION Xapian::DB_CREATE_OR_OPEN
#endif
+#define LOG_XAPIAN_EXCEPTION(message, error) IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n", error.get_msg ().c_str ()));
+
notmuch_status_t
notmuch_database_open (const char *path,
notmuch_database_mode_t mode,
@@ -154,7 +156,8 @@ 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;
+ const char *notmuch_path, *xapian_path;
+ char *incompat_features;
char *message = NULL;
struct stat st;
int err;
@@ -190,25 +193,41 @@ notmuch_database_open_with_config (const char *database_path,
notmuch->writable_xapian_db = NULL;
notmuch->atomic_nesting = 0;
notmuch->view = 1;
+ notmuch->xapian_db = NULL;
- if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
- message = strdup ("Out of memory\n");
- status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ try {
+ xapian_path = talloc_asprintf (notmuch,"%s/xapian",database_path);
+ notmuch->xapian_db = new Xapian::Database (xapian_path);
+ } catch (const Xapian::DatabaseOpeningError &error) {
+ notmuch->xapian_db = NULL;
+ } catch (const Xapian::Error &error) {
+ LOG_XAPIAN_EXCEPTION (message, error);
+ notmuch_database_destroy (notmuch);
+ notmuch = NULL;
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
goto DONE;
}
- err = stat (notmuch_path, &st);
- if (err) {
- IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
- notmuch_path, strerror (errno)));
- status = NOTMUCH_STATUS_FILE_ERROR;
- goto DONE;
- }
+ if (! notmuch->xapian_db) {
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
+ message = strdup ("Out of memory\n");
+ status = NOTMUCH_STATUS_OUT_OF_MEMORY;
+ 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;
+ err = stat (notmuch_path, &st);
+ if (err) {
+ IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
+ notmuch_path, strerror (errno)));
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ 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;
+ }
}
try {
@@ -216,11 +235,16 @@ notmuch_database_open_with_config (const char *database_path,
std::string last_mod;
if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
+ /* get rid of read only version opened above */
+ if (notmuch->xapian_db)
+ delete notmuch->xapian_db;
+
notmuch->writable_xapian_db = new Xapian::WritableDatabase (xapian_path,
DB_ACTION);
notmuch->xapian_db = notmuch->writable_xapian_db;
} else {
- notmuch->xapian_db = new Xapian::Database (xapian_path);
+ if (! notmuch->xapian_db)
+ notmuch->xapian_db = new Xapian::Database (xapian_path);
}
/* Check version. As of database version 3, we represent
@@ -318,8 +342,7 @@ notmuch_database_open_with_config (const char *database_path,
goto DONE;
} catch (const Xapian::Error &error) {
- IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
- error.get_msg ().c_str ()));
+ LOG_XAPIAN_EXCEPTION (message, error);
notmuch_database_destroy (notmuch);
notmuch = NULL;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 190b3686..72c369cb 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -40,4 +40,13 @@ output=$(notmuch count '*')
test_expect_equal "$output" '52'
restore_database
+backup_database
+test_begin_subtest "split (no prefix)"
+notmuch config set database.path `pwd`/database
+notmuch config set database.mail_root `pwd`/mail
+mv mail/.notmuch/xapian database
+output=$(notmuch count '*')
+test_expect_equal "$output" '52'
+restore_database
+
test_done
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] lib/open: support XDG_DATA_HOME as a fallback database location.
2021-01-05 2:23 v1 flexible database location David Bremner
` (3 preceding siblings ...)
2021-01-05 2:23 ` [PATCH 4/5] lib/open: open xapian database without .notmuch prefix David Bremner
@ 2021-01-05 2:23 ` David Bremner
4 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2021-01-05 2:23 UTC (permalink / raw)
To: notmuch; +Cc: David Bremner
This changes some error reporting, either intentionally by reporting
the highest level missing directory, or by side effect from looking in
XDG locations when given null database location.
---
lib/open.cc | 25 +++++++++++++++++++------
test/T055-path-config.sh | 11 +++++++++++
test/T560-lib-error.sh | 6 +++---
test/T590-libconfig.sh | 4 ++--
4 files changed, 35 insertions(+), 11 deletions(-)
diff --git a/lib/open.cc b/lib/open.cc
index 91b24e38..bc97e178 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -116,7 +116,8 @@ DONE:
}
static notmuch_status_t
-_pre_open(const char *config_path,
+_pre_open(void *ctx,
+ const char *config_path,
const char *profile,
GKeyFile **key_file,
const char **database_path,
@@ -133,6 +134,10 @@ _pre_open(const char *config_path,
if (! *database_path && *key_file)
*database_path = g_key_file_get_value (*key_file, "database", "path", NULL);
+ if (! *database_path) {
+ *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
+ }
+
if (*database_path == NULL) {
*message = strdup ("Error: Cannot open a database for a NULL path.\n");
return NOTMUCH_STATUS_NULL_POINTER;
@@ -169,7 +174,7 @@ notmuch_database_open_with_config (const char *database_path,
database_path = getenv ("NOTMUCH_DATABASE");
}
- if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
+ if ((status = _pre_open (local, config_path, profile, &key_file, &database_path, &message)))
goto DONE;
/* Initialize the GLib type system and threads */
@@ -195,6 +200,14 @@ notmuch_database_open_with_config (const char *database_path,
notmuch->view = 1;
notmuch->xapian_db = NULL;
+ err = stat (database_path, &st);
+ if (err) {
+ IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n",
+ database_path, strerror (errno)));
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
+
try {
xapian_path = talloc_asprintf (notmuch,"%s/xapian",database_path);
notmuch->xapian_db = new Xapian::Database (xapian_path);
@@ -408,8 +421,9 @@ notmuch_database_create_with_config (const char *database_path,
GKeyFile *key_file = NULL;
struct stat st;
int err;
+ void *local = talloc_new (NULL);
- if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message)))
+ if ((status = _pre_open (local, config_path, profile, &key_file, &database_path, &message)))
goto DONE;
err = stat (database_path, &st);
@@ -428,7 +442,7 @@ notmuch_database_create_with_config (const char *database_path,
goto DONE;
}
- notmuch_path = talloc_asprintf (NULL, "%s/%s", database_path, ".notmuch");
+ notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch");
err = mkdir (notmuch_path, 0755);
if (err) {
@@ -464,8 +478,7 @@ notmuch_database_create_with_config (const char *database_path,
}
DONE:
- if (notmuch_path)
- talloc_free (notmuch_path);
+ talloc_free (local);
if (message) {
if (status_string)
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 72c369cb..b4bc6741 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -49,4 +49,15 @@ output=$(notmuch count '*')
test_expect_equal "$output" '52'
restore_database
+backup_database
+test_begin_subtest "xdg database location"
+notmuch config set database.mail_root `pwd`/mail
+notmuch config set database.path
+dir=home/.local/share/notmuch/default/
+mkdir -p $dir
+mv mail/.notmuch/xapian $dir
+output=$(notmuch count '*')
+test_expect_equal "$output" '52'
+restore_database
+
test_done
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index ade376ef..9b59fb55 100755
--- a/test/T560-lib-error.sh
+++ b/test/T560-lib-error.sh
@@ -22,7 +22,7 @@ EOF
cat <<'EOF' >EXPECTED
== stdout ==
== stderr ==
-Error: Cannot open a database for a NULL path.
+Error opening database at CWD/home/.local/share/notmuch/default: No such file or directory
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -76,7 +76,7 @@ EOF
cat <<'EOF' >EXPECTED
== stdout ==
== stderr ==
-Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory
+Error opening database at CWD/nonexistent/foo: No such file or directory
EOF
test_expect_equal_file EXPECTED OUTPUT
@@ -93,7 +93,7 @@ EOF
cat <<'EOF' >EXPECTED
== stdout ==
== stderr ==
-Error: Cannot open a database for a NULL path.
+Error: Cannot create database at CWD/home/.local/share/notmuch/default: No such file or directory.
EOF
test_expect_equal_file EXPECTED OUTPUT
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index b03ee0c6..256b9463 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -487,8 +487,8 @@ cat <<'EOF' >EXPECTED
== stdout ==
== stderr ==
error opening database
-Erroneous NULL pointer
-Error: Cannot open a database for a NULL path.
+Something went wrong trying to read or write a file
+Error opening database at CWD/home/.local/share/notmuch/default: No such file or directory
EOF
test_expect_equal_file EXPECTED OUTPUT
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH] fixup! support splitting mail from database location.
2021-01-05 2:23 ` [PATCH 2/5] support splitting mail from database location David Bremner
@ 2021-01-07 11:50 ` David Bremner
0 siblings, 0 replies; 7+ messages in thread
From: David Bremner @ 2021-01-07 11:50 UTC (permalink / raw)
To: David Bremner, notmuch
---
notmuch-insert.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/notmuch-insert.c b/notmuch-insert.c
index e483b949..4ae65d4d 100644
--- a/notmuch-insert.c
+++ b/notmuch-insert.c
@@ -448,7 +448,7 @@ notmuch_insert_command (unused(notmuch_config_t *config),notmuch_database_t *not
{
notmuch_status_t status, close_status;
struct sigaction action;
- const char *db_path;
+ const char *db_path, *mail_root;
notmuch_config_values_t *new_tags = NULL;
tag_op_list_t *tag_ops;
char *query_string = NULL;
@@ -489,6 +489,8 @@ notmuch_insert_command (unused(notmuch_config_t *config),notmuch_database_t *not
else
db_path = talloc_strdup (local, db_path);
+ mail_root = notmuch_config_get (notmuch, NOTMUCH_CONFIG_MAIL_ROOT);
+
new_tags = notmuch_config_get_values (notmuch, NOTMUCH_CONFIG_NEW_TAGS);
if (print_status_database (
@@ -533,7 +535,7 @@ notmuch_insert_command (unused(notmuch_config_t *config),notmuch_database_t *not
return EXIT_FAILURE;
}
- maildir = talloc_asprintf (local, "%s/%s", db_path, folder);
+ maildir = talloc_asprintf (local, "%s/%s", mail_root, folder);
if (! maildir) {
fprintf (stderr, "Out of memory\n");
return EXIT_FAILURE;
--
2.29.2
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-01-07 11:50 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-05 2:23 v1 flexible database location David Bremner
2021-01-05 2:23 ` [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
2021-01-05 2:23 ` [PATCH 2/5] support splitting mail from database location David Bremner
2021-01-07 11:50 ` [PATCH] fixup! " David Bremner
2021-01-05 2:23 ` [PATCH 3/5] lib/open: move path calculations after notmuch object creation David Bremner
2021-01-05 2:23 ` [PATCH 4/5] lib/open: open xapian database without .notmuch prefix David Bremner
2021-01-05 2:23 ` [PATCH 5/5] lib/open: support XDG_DATA_HOME as a fallback database location 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).