Although this default worked for "notmuch config get", it didn't work
most other places. Restore the previous functionality, with the
wrinkle that XDG locations will shadow $HOME/mail if they exist.

This fixes a bug reported by Jack Kamm in id:[email protected]
---
 lib/open.cc              | 19 ++++++++++++++++++-
 test/T055-path-config.sh | 22 ++++++++++++++++++++--
 test/T560-lib-error.sh   |  4 ++--
 test/T590-libconfig.sh   |  4 ++--
 4 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/lib/open.cc b/lib/open.cc
index bdb695fe..d7d2bedb 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -209,8 +209,25 @@ _choose_database_path (void *ctx,
        }
     }
     if (! *database_path) {
+       notmuch_status_t status;
+
        *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", 
profile);
-       *split = true;
+       status = _db_dir_exists (*database_path, message);
+       if (status) {
+           *database_path = NULL;
+       } else {
+           *split = true;
+       }
+    }
+
+    if (! *database_path) {
+       notmuch_status_t status;
+
+       *database_path = talloc_asprintf (ctx, "%s/mail", getenv ("HOME"));
+       status = _db_dir_exists (*database_path, message);
+       if (status) {
+           *database_path = NULL;
+       }
     }
 
     if (*database_path == NULL) {
diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh
index 2045a555..8ef76aed 100755
--- a/test/T055-path-config.sh
+++ b/test/T055-path-config.sh
@@ -16,6 +16,7 @@ restore_config () {
     unset DATABASE_PATH
     unset NOTMUCH_PROFILE
     unset XAPIAN_PATH
+    rm -f "$HOME/mail"
     cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
 }
 
@@ -42,6 +43,18 @@ symlink_config () {
     unset DATABASE_PATH
 }
 
+
+home_mail_config () {
+    local dir
+    backup_config
+    dir="${HOME}/mail"
+    ln -s $MAIL_DIR $dir
+    notmuch config set database.path
+    notmuch config set database.mail_root
+    XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian"
+    unset DATABASE_PATH
+}
+
 xdg_config () {
     local dir
     local profile=${1:-default}
@@ -66,7 +79,7 @@ xdg_config () {
     notmuch --config=${CONFIG_PATH} config set database.path
 }
 
-for config in traditional split XDG XDG+profile symlink; do
+for config in traditional split XDG XDG+profile symlink home_mail; do
     #start each set of tests with an known set of messages
     add_email_corpus
 
@@ -90,6 +103,9 @@ for config in traditional split XDG XDG+profile symlink; do
        symlink)
            symlink_config
            ;;
+       home_mail)
+           home_mail_config
+           ;;
     esac
 
     test_begin_subtest "count ($config)"
@@ -236,7 +252,9 @@ EOF
    test_begin_subtest "Config list ($config)"
    notmuch config list | notmuch_dir_sanitize | sed -e 
"s/^database.backup_dir=.*$/database.backup_dir/"  \
                                                    -e 
"s/^database.hook_dir=.*$/database.hook_dir/" \
-                                                   -e 
"s/^database.path=.*$/database.path/" > OUTPUT
+                                                   -e 
"s/^database.path=.*$/database.path/"  \
+                                                   -e 
"s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \
+                                                   > OUTPUT
    cat <<EOF > EXPECTED
 built_with.compact=true
 built_with.field_processor=true
diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh
index 89447e9a..1f4482cb 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 database at CWD/home/.local/share/notmuch/default: No such 
file or directory.
+Error: could not locate database.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
@@ -93,7 +93,7 @@ EOF
 cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
-Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such 
file or directory.
+Error: could not locate database.
 EOF
 test_expect_equal_file EXPECTED OUTPUT
 
diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh
index 51dd29c8..745e1bb4 100755
--- a/test/T590-libconfig.sh
+++ b/test/T590-libconfig.sh
@@ -546,8 +546,8 @@ cat <<'EOF' >EXPECTED
 == stdout ==
 == stderr ==
 error opening database
-Something went wrong trying to read or write a file
-Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such 
file or directory.
+No database found
+Error: could not locate database.
 
 EOF
 test_expect_equal_file EXPECTED OUTPUT
-- 
2.30.2
_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to