From bfe4555325086d5cb99e3962424128f94d1c921d Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 11 Jun 2011 00:07:54 -0400 Subject: lib: Remove message document directly after removing the last file name. Previously, notmuch_database_remove_message would remove the message file name, sync the change to the message document, re-find the message document, and then delete it if there were no more file names. An interruption after sync'ing would result in a file-name-less, permanently un-removable zombie message that would produce errors and odd results in searches. We could wrap this in an atomic section, but it's much simpler to eliminate the round-about approach and just delete the message document instead of sync'ing it if we removed the last filename. --- lib/message.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib/message.cc') diff --git a/lib/message.cc b/lib/message.cc index 20b77580..531d3043 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -822,6 +822,22 @@ _notmuch_message_sync (notmuch_message_t *message) db->replace_document (message->doc_id, message->doc); } +/* Delete a message document from the database. */ +notmuch_status_t +_notmuch_message_delete (notmuch_message_t *message) +{ + notmuch_status_t status; + Xapian::WritableDatabase *db; + + status = _notmuch_database_ensure_writable (message->notmuch); + if (status) + return status; + + db = static_cast (message->notmuch->xapian_db); + db->delete_document (message->doc_id); + return NOTMUCH_STATUS_SUCCESS; +} + /* Ensure that 'message' is not holding any file object open. Future * calls to various functions will still automatically open the * message file as needed. -- cgit v1.2.3