From: David Bremner <david@tethera.net>
To: Jack Kamm <jackkamm@gmail.com>, notmuch@notmuchmail.org
Cc: David Bremner <david@tethera.net>
Subject: [PATCH] lib/open: restore default database path of $HOME/mail
Date: Mon, 10 May 2021 07:39:18 -0300 [thread overview]
Message-ID: <20210510103918.56511-1-david@tethera.net> (raw)
In-Reply-To: <87eeefdc8b.fsf@gmail.com>
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:87eeefdc8b.fsf@gmail.com
---
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
next prev parent reply other threads:[~2021-05-10 10:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-09 14:58 Breakage after updating to 0.32 (database and path issues) Jack Kamm
2021-05-09 17:51 ` David Bremner
2021-05-09 18:08 ` Jack Kamm
2021-05-09 17:54 ` Jack Kamm
2021-05-09 18:52 ` Jack Kamm
2021-05-10 10:39 ` David Bremner [this message]
2021-05-15 12:12 ` [PATCH] lib/open: restore default database path of $HOME/mail David Bremner
2021-05-10 10:50 ` Breakage after updating to 0.32 (database and path issues) David Bremner
2021-05-16 23:50 ` Jack Kamm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210510103918.56511-1-david@tethera.net \
--to=david@tethera.net \
--cc=jackkamm@gmail.com \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).