mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 04:18:08 +01:00
lib/open: restore default database path of $HOME/mail
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
This commit is contained in:
parent
0e8795b28c
commit
b3258244c8
4 changed files with 42 additions and 7 deletions
17
lib/open.cc
17
lib/open.cc
|
@ -209,9 +209,26 @@ _choose_database_path (void *ctx,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! *database_path) {
|
if (! *database_path) {
|
||||||
|
notmuch_status_t status;
|
||||||
|
|
||||||
*database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
|
*database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile);
|
||||||
|
status = _db_dir_exists (*database_path, message);
|
||||||
|
if (status) {
|
||||||
|
*database_path = NULL;
|
||||||
|
} else {
|
||||||
*split = true;
|
*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) {
|
if (*database_path == NULL) {
|
||||||
*message = strdup ("Error: could not locate database.\n");
|
*message = strdup ("Error: could not locate database.\n");
|
||||||
|
|
|
@ -16,6 +16,7 @@ restore_config () {
|
||||||
unset DATABASE_PATH
|
unset DATABASE_PATH
|
||||||
unset NOTMUCH_PROFILE
|
unset NOTMUCH_PROFILE
|
||||||
unset XAPIAN_PATH
|
unset XAPIAN_PATH
|
||||||
|
rm -f "$HOME/mail"
|
||||||
cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
|
cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +43,18 @@ symlink_config () {
|
||||||
unset DATABASE_PATH
|
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 () {
|
xdg_config () {
|
||||||
local dir
|
local dir
|
||||||
local profile=${1:-default}
|
local profile=${1:-default}
|
||||||
|
@ -66,7 +79,7 @@ xdg_config () {
|
||||||
notmuch --config=${CONFIG_PATH} config set database.path
|
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
|
#start each set of tests with an known set of messages
|
||||||
add_email_corpus
|
add_email_corpus
|
||||||
|
|
||||||
|
@ -90,6 +103,9 @@ for config in traditional split XDG XDG+profile symlink; do
|
||||||
symlink)
|
symlink)
|
||||||
symlink_config
|
symlink_config
|
||||||
;;
|
;;
|
||||||
|
home_mail)
|
||||||
|
home_mail_config
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
test_begin_subtest "count ($config)"
|
test_begin_subtest "count ($config)"
|
||||||
|
@ -236,7 +252,9 @@ EOF
|
||||||
test_begin_subtest "Config list ($config)"
|
test_begin_subtest "Config list ($config)"
|
||||||
notmuch config list | notmuch_dir_sanitize | sed -e "s/^database.backup_dir=.*$/database.backup_dir/" \
|
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.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
|
cat <<EOF > EXPECTED
|
||||||
built_with.compact=true
|
built_with.compact=true
|
||||||
built_with.field_processor=true
|
built_with.field_processor=true
|
||||||
|
|
|
@ -22,7 +22,7 @@ EOF
|
||||||
cat <<'EOF' >EXPECTED
|
cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
== stderr ==
|
== stderr ==
|
||||||
Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory.
|
Error: could not locate database.
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ EOF
|
||||||
cat <<'EOF' >EXPECTED
|
cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
== stderr ==
|
== stderr ==
|
||||||
Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory.
|
Error: could not locate database.
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
||||||
|
|
|
@ -546,8 +546,8 @@ cat <<'EOF' >EXPECTED
|
||||||
== stdout ==
|
== stdout ==
|
||||||
== stderr ==
|
== stderr ==
|
||||||
error opening database
|
error opening database
|
||||||
Something went wrong trying to read or write a file
|
No database found
|
||||||
Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory.
|
Error: could not locate database.
|
||||||
|
|
||||||
EOF
|
EOF
|
||||||
test_expect_equal_file EXPECTED OUTPUT
|
test_expect_equal_file EXPECTED OUTPUT
|
||||||
|
|
Loading…
Reference in a new issue