From: David Bremner Date: Fri, 19 Mar 2021 01:58:02 +0000 (-0300) Subject: CLI/new: drop the write lock to run the pre-new hook. X-Git-Tag: 0.32_rc0~57 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=a9f74aeeb9ade477d5b80c1c2700945d6c50adb1 CLI/new: drop the write lock to run the pre-new hook. This fixes a bug reported in [1]. In principle it could be possible avoid one of these reopens, but it complicates the logic in main with respect to creating new databases. [1]: id:9C1993DF-84BD-4199-A9C8-BADA98498812@bubblegen.co.uk --- diff --git a/notmuch-new.c b/notmuch-new.c index 223d68bb..8214fb23 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1170,9 +1170,19 @@ notmuch_new_command (unused(notmuch_config_t *config), notmuch_database_t *notmu } if (hooks) { + /* Drop write lock to run hook */ + status = notmuch_database_reopen (notmuch, NOTMUCH_DATABASE_MODE_READ_ONLY); + if (print_status_database ("notmuch new", notmuch, status)) + return EXIT_FAILURE; + ret = notmuch_run_hook (notmuch, "pre-new"); if (ret) return EXIT_FAILURE; + + /* acquire write lock again */ + status = notmuch_database_reopen (notmuch, NOTMUCH_DATABASE_MODE_READ_WRITE); + if (print_status_database ("notmuch new", notmuch, status)) + return EXIT_FAILURE; } notmuch_exit_if_unmatched_db_uuid (notmuch); diff --git a/test/T400-hooks.sh b/test/T400-hooks.sh index a2b67d59..de8e4ba4 100755 --- a/test/T400-hooks.sh +++ b/test/T400-hooks.sh @@ -159,7 +159,6 @@ EOF test_expect_equal_file write.expected write.output test_begin_subtest "pre-new with write access [${config}]" - test_subtest_known_broken rm -rf ${HOOK_DIR} create_write_hook "pre-new" write.expected write.output $HOOK_DIR NOTMUCH_NEW