From: David Bremner Date: Sun, 4 Dec 2022 02:28:57 +0000 (-0400) Subject: lib/message: move xapian call inside try/catch block in _n_m_delete X-Git-Tag: 0.38_rc0~57 X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=commitdiff_plain;h=1d5d0ae68689e7b1d6b974e275f19371250c4b25 lib/message: move xapian call inside try/catch block in _n_m_delete The call to delete_document can throw exceptions (and can happen in practice [1]), so catch the exception and extract the error message. As a side effect, also move the call to _n_m_has_term inside the try/catch. This should not change anything as that function already traps any Xapian exceptions. [1]: id:wwuk039sk2p.fsf@chaotikum.eu --- diff --git a/lib/message.cc b/lib/message.cc index 1c87f8c0..5ccca95a 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -1383,21 +1383,21 @@ _notmuch_message_delete (notmuch_message_t *message) if (status) return status; - message->notmuch->writable_xapian_db->delete_document (message->doc_id); - - /* if this was a ghost to begin with, we are done */ - private_status = _notmuch_message_has_term (message, "type", "ghost", &is_ghost); - if (private_status) - return COERCE_STATUS (private_status, - "Error trying to determine whether message was a ghost"); - if (is_ghost) - return NOTMUCH_STATUS_SUCCESS; - - /* look for a non-ghost message in the same thread */ try { Xapian::PostingIterator thread_doc, thread_doc_end; Xapian::PostingIterator mail_doc, mail_doc_end; + message->notmuch->writable_xapian_db->delete_document (message->doc_id); + + /* look for a non-ghost message in the same thread */ + /* if this was a ghost to begin with, we are done */ + private_status = _notmuch_message_has_term (message, "type", "ghost", &is_ghost); + if (private_status) + return COERCE_STATUS (private_status, + "Error trying to determine whether message was a ghost"); + if (is_ghost) + return NOTMUCH_STATUS_SUCCESS; + _notmuch_database_find_doc_ids (message->notmuch, "thread", tid, &thread_doc, &thread_doc_end); _notmuch_database_find_doc_ids (message->notmuch, "type", "mail", &mail_doc, &mail_doc_end); diff --git a/test/T566-lib-message.sh b/test/T566-lib-message.sh index 562ab05a..7f0e8eb0 100755 --- a/test/T566-lib-message.sh +++ b/test/T566-lib-message.sh @@ -518,7 +518,6 @@ test_expect_equal_file EXPECTED OUTPUT TERMLIST_PATH=(${MAIL_DIR}/.notmuch/xapian/termlist.*) test_begin_subtest "remove message with corrupted db" -test_subtest_known_broken backup_database cat c_head0 - c_tail <<'EOF' | test_private_C ${MAIL_DIR} ${TERMLIST_PATH} {