aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2021-05-10 11:36:56 -0300
committerDavid Bremner <david@tethera.net>2021-05-10 11:36:56 -0300
commitb4a4ed0df9cd2150e75853f5491cfa02fe72caf1 (patch)
tree0090f337227ba5d2e06966f8074c540aea914d66
parentac64de450a4d61c49fef509ce376fc4d096bb5b5 (diff)
parent5ebbf17242522e3a00d7f084f0ddfc86b0611825 (diff)
Merge branch 'release'
-rw-r--r--NEWS7
-rw-r--r--doc/man1/notmuch-config.rst12
-rw-r--r--lib/config.cc30
-rwxr-xr-xtest/T030-config.sh6
-rwxr-xr-xtest/T050-new.sh24
-rwxr-xr-xtest/T400-hooks.sh7
-rwxr-xr-xtest/T530-upgrade.sh19
7 files changed, 96 insertions, 9 deletions
diff --git a/NEWS b/NEWS
index 96765c73..081c6089 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,13 @@ Vim
Respect excluded tags when showing a thread.
+Notmuch 0.32.1 (UNRELEASED)
+===========================
+
+Restore handling of relative values for `database.path` that was
+broken by 0.32. Extend this handling to `database.mail_root`,
+`database.backup_dir`, and `database.hook_dir`.
+
Notmuch 0.32 (2021-05-02)
=========================
diff --git a/doc/man1/notmuch-config.rst b/doc/man1/notmuch-config.rst
index 32290a38..75c59ff9 100644
--- a/doc/man1/notmuch-config.rst
+++ b/doc/man1/notmuch-config.rst
@@ -44,7 +44,9 @@ configuration file and corresponding database.
characters. In a multiple-value item (a list), the values are
separated by semicolon characters.
-The available configuration items are described below.
+The available configuration items are described below. Non-absolute
+paths are presumed relative to `$HOME` for items in section
+**database**.
**database.path**
Notmuch will store its database here, (in
@@ -63,6 +65,14 @@ The available configuration items are described below.
Default: For compatibility with older configurations, the value of
database.path is used if **database.mail\_root** is unset.
+**database.backup_dir**
+ Directory to store tag dumps when upgrading database.
+
+ History: this configuration value was introduced in notmuch 0.32.
+
+ Default: A sibling directory of the Xapian database called
+ `backups`.
+
**database.hook_dir**
Directory containing hooks run by notmuch commands. See
diff --git a/lib/config.cc b/lib/config.cc
index 50bcf6a2..0ec66372 100644
--- a/lib/config.cc
+++ b/lib/config.cc
@@ -46,6 +46,7 @@ struct _notmuch_config_pairs {
};
static const char *_notmuch_config_key_to_string (notmuch_config_key_t key);
+static char *_expand_path (void *ctx, const char *key, const char *val);
static int
_notmuch_config_list_destroy (notmuch_config_list_t *list)
@@ -257,9 +258,10 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch)
return status;
for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
- _notmuch_string_map_append (notmuch->config,
- notmuch_config_list_key (list),
- notmuch_config_list_value (list));
+ const char *key = notmuch_config_list_key (list);
+ char *normalized_val = _expand_path (list, key, notmuch_config_list_value (list));
+ _notmuch_string_map_append (notmuch->config, key, normalized_val);
+ talloc_free (normalized_val);
}
return status;
@@ -387,6 +389,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs)
talloc_free (pairs);
}
+static char *
+_expand_path (void *ctx, const char *key, const char *val)
+{
+ char *expanded_val;
+
+ if ((strcmp (key, "database.path") == 0 ||
+ strcmp (key, "database.mail_root") == 0 ||
+ strcmp (key, "database.hook_dir") == 0 ||
+ strcmp (key, "database.backup_path") == 0 ) &&
+ val[0] != '/')
+ expanded_val = talloc_asprintf (ctx, "%s/%s", getenv ("HOME"), val);
+ else
+ expanded_val = talloc_strdup (ctx, val);
+
+ return expanded_val;
+}
+
notmuch_status_t
_notmuch_config_load_from_file (notmuch_database_t *notmuch,
GKeyFile *file)
@@ -407,14 +426,17 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
keys = g_key_file_get_keys (file, *grp, NULL, NULL);
for (gchar **keys_p = keys; *keys_p; keys_p++) {
char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *keys_p);
+ char *normalized_val;
val = g_key_file_get_value (file, *grp, *keys_p, NULL);
if (! val) {
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
- _notmuch_string_map_set (notmuch->config, absolute_key, val);
+ normalized_val = _expand_path (notmuch, absolute_key, val);
+ _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val);
g_free (val);
talloc_free (absolute_key);
+ talloc_free (normalized_val);
if (status)
goto DONE;
}
diff --git a/test/T030-config.sh b/test/T030-config.sh
index b22d8f29..7a1660e9 100755
--- a/test/T030-config.sh
+++ b/test/T030-config.sh
@@ -117,12 +117,12 @@ test_expect_equal "$(notmuch config get database.path)" \
ln -s `pwd`/mail home/Maildir
add_email_corpus
-test_begin_subtest "Relative database path expanded in open"
+test_begin_subtest "Relative database path expanded"
notmuch config set database.path Maildir
-path=$(notmuch config get database.path)
+path=$(notmuch config get database.path | notmuch_dir_sanitize)
count=$(notmuch count '*')
test_expect_equal "${path} ${count}" \
- "Maildir 52"
+ "CWD/home/Maildir 52"
test_begin_subtest "Add config to database"
notmuch new
diff --git a/test/T050-new.sh b/test/T050-new.sh
index 2985e24c..4beae379 100755
--- a/test/T050-new.sh
+++ b/test/T050-new.sh
@@ -394,6 +394,30 @@ exit status: 75
EOF
test_expect_equal_file EXPECTED OUTPUT
+test_begin_subtest "Relative database path expanded in new"
+ln -s "$PWD/mail" home/Maildir
+notmuch config set database.path Maildir
+generate_message
+NOTMUCH_NEW > OUTPUT
+cat <<EOF >EXPECTED
+Added 1 new message to the database.
+EOF
+notmuch config set database.path ${MAIL_DIR}
+rm home/Maildir
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "Relative mail root (in db) expanded in new"
+ln -s "$PWD/mail" home/Maildir
+notmuch config set --database database.mail_root Maildir
+generate_message
+NOTMUCH_NEW > OUTPUT
+cat <<EOF >EXPECTED
+Added 1 new message to the database.
+EOF
+notmuch config set database.mail_root
+rm home/Maildir
+test_expect_equal_file EXPECTED OUTPUT
+
add_email_corpus broken
test_begin_subtest "reference loop does not crash"
test_expect_code 0 "notmuch show --format=json id:mid-loop-12@example.org id:mid-loop-21@example.org > OUTPUT"
diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh
index 3a2df2f4..00c99337 100755
--- a/test/T400-hooks.sh
+++ b/test/T400-hooks.sh
@@ -43,7 +43,7 @@ add_message
# create maildir structure for notmuch-insert
mkdir -p "$MAIL_DIR"/{cur,new,tmp}
-for config in traditional profile explicit XDG split; do
+for config in traditional profile explicit relative XDG split; do
unset NOTMUCH_PROFILE
notmuch config set database.hook_dir
notmuch config set database.path ${MAIL_DIR}
@@ -63,6 +63,11 @@ for config in traditional profile explicit XDG split; do
mkdir -p $HOOK_DIR
notmuch config set database.hook_dir $HOOK_DIR
;;
+ relative)
+ HOOK_DIR=${HOME}/.notmuch-hooks
+ mkdir -p $HOOK_DIR
+ notmuch config set database.hook_dir .notmuch-hooks
+ ;;
XDG)
HOOK_DIR=${HOME}/.config/notmuch/default/hooks
;;
diff --git a/test/T530-upgrade.sh b/test/T530-upgrade.sh
index cce29f45..5f0de2ed 100755
--- a/test/T530-upgrade.sh
+++ b/test/T530-upgrade.sh
@@ -54,4 +54,23 @@ for key in 'from/subject/message-ID in database' \
restore_database
done
+test_begin_subtest "upgrade with configured backup dir"
+notmuch config set database.backup_dir ${HOME}/backups
+delete_feature 'modification tracking'
+notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
+cat <<EOF > EXPECTED
+Backing up tags to CWD/home/backups/dump-XXX.gz...
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+test_begin_subtest "upgrade with relative configured backup dir"
+notmuch config set database.backup_dir ${HOME}/backups
+delete_feature 'modification tracking'
+notmuch new | grep Backing | notmuch_dir_sanitize | sed 's/dump-[0-9T]*/dump-XXX/' > OUTPUT
+cat <<EOF > EXPECTED
+Backing up tags to CWD/home/backups/dump-XXX.gz...
+EOF
+test_expect_equal_file EXPECTED OUTPUT
+
+
test_done