]> git.cworth.org Git - notmuch/commitdiff
Merge branch 'release'
authorDavid Bremner <david@tethera.net>
Mon, 10 May 2021 14:36:56 +0000 (11:36 -0300)
committerDavid Bremner <david@tethera.net>
Mon, 10 May 2021 14:36:56 +0000 (11:36 -0300)
NEWS
doc/man1/notmuch-config.rst
lib/config.cc
test/T030-config.sh
test/T050-new.sh
test/T400-hooks.sh
test/T530-upgrade.sh

diff --git a/NEWS b/NEWS
index 96765c7335e932c5916ab9b0eb23caef60d8b11a..081c60896d2dc467e67c8293b70493b4db61e437 100644 (file)
--- 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)
 =========================
 
index 32290a38a3e60605230e24e0dbab651b97effc5d..75c59ff971880b198ab4aff499ed4c983d11860c 100644 (file)
@@ -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
index 50bcf6a28c43037099a616af432081aa25018658..0ec66372dec7d2f2e7a0f30eede8db40c86c88d2 100644 (file)
@@ -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;
        }
index b22d8f291f5c0dfae01aeae5274281fca3112857..7a1660e9be29d8550a414aafdfd48c47ead86d42 100755 (executable)
@@ -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
index 2985e24c66beb9ce13816ebdacf85c5a9638e139..4beae3799c53e310f9ccb01895b85fa85ccd1898 100755 (executable)
@@ -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"
index 3a2df2f4efabe5c7c097a2d6240ac75f80305c7c..00c993379c3af1d6605985cecbeea6eeac718ec7 100755 (executable)
@@ -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
            ;;
index cce29f4580855044f51ea23cb341191f19e0436f..5f0de2edb772743aa2065b7e50dd4bf03a91df9c 100755 (executable)
@@ -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