lib/open: fix hook directory calculation in split configuration

Choose sibling directory of xapian database, as .notmuch may not
exist.

libgen.h is already used in debugger.c, so it is not a new dependency
/ potential portability problem.
This commit is contained in:
David Bremner 2021-02-17 07:16:54 -04:00
parent b30a59157d
commit e3a4abc513
2 changed files with 12 additions and 3 deletions

View file

@ -1,4 +1,6 @@
#include <unistd.h> #include <unistd.h>
#include <libgen.h>
#include "database-private.h" #include "database-private.h"
#include "parse-time-vrp.h" #include "parse-time-vrp.h"
@ -92,8 +94,8 @@ _choose_hook_dir (notmuch_database_t *notmuch,
err = stat (hook_dir, &st); err = stat (hook_dir, &st);
if (err) { if (err) {
if (errno == ENOENT) { if (errno == ENOENT) {
const char *database_path = notmuch_database_get_path (notmuch); char *notmuch_path = dirname (talloc_strdup (notmuch, notmuch->xapian_path));
hook_dir = talloc_asprintf (notmuch, "%s/.notmuch/hooks", database_path); hook_dir = talloc_asprintf (notmuch, "%s/hooks", notmuch_path);
} else { } else {
IGNORE_RESULT (asprintf (message, "Error: Cannot stat %s: %s.\n", IGNORE_RESULT (asprintf (message, "Error: Cannot stat %s: %s.\n",
hook_dir, strerror (errno))); hook_dir, strerror (errno)));

View file

@ -43,9 +43,10 @@ add_message
# create maildir structure for notmuch-insert # create maildir structure for notmuch-insert
mkdir -p "$MAIL_DIR"/{cur,new,tmp} mkdir -p "$MAIL_DIR"/{cur,new,tmp}
for config in traditional profile explicit XDG; do for config in traditional profile explicit XDG split; do
unset NOTMUCH_PROFILE unset NOTMUCH_PROFILE
notmuch config set database.hook_dir notmuch config set database.hook_dir
notmuch config set database.path ${MAIL_DIR}
case $config in case $config in
traditional) traditional)
HOOK_DIR=${MAIL_DIR}/.notmuch/hooks HOOK_DIR=${MAIL_DIR}/.notmuch/hooks
@ -65,6 +66,12 @@ for config in traditional profile explicit XDG; do
XDG) XDG)
HOOK_DIR=${HOME}/.config/notmuch/default/hooks HOOK_DIR=${HOME}/.config/notmuch/default/hooks
;; ;;
split)
dir="$TMP_DIRECTORY/database.$test_count"
notmuch config set database.path $dir
notmuch config set database.mail_root $MAIL_DIR
HOOK_DIR=${dir}/hooks
;;
esac esac
test_begin_subtest "pre-new is run [${config}]" test_begin_subtest "pre-new is run [${config}]"