Here's the reworked patch series that uses atomic sections more heavily rather than changing the removal API. This is atomic-new-v6 on http://awakening.csail.mit.edu/git/notmuch.git . (I was planning to make this series on Monday while stuck on a plane, but an opportunity presented itself when I needed something better to do than fix the sink. As a result, if you can look over this before Monday, I can use that time to address any further comments.) The beginning of the sequence---"test: Fix message when skipping test_expect_equal* tests" through "new: Defer updating directory mtimes until the end."---has not changed besides than the minor things you pointed out earlier. Here's a quick summary of the differences in the rest of the sequence: lib: Add notmuch_database_{begin,end}_atomic. Rebased but otherwise identical. lib: Add support for nested atomic sections. New. lib: Indicate if there are more filenames after removal. Rebased but otherwise identical. lib: Remove message document directly after removing the last file name. New. Supersedes the patches that rewrote notmuch_database_remove_message and made sync delete messages. lib: Add an API to find a message by filename. Culled from "lib: Add API's to find by filename and ..." in the old series. What I kept is identical. lib: Wrap notmuch_database_add_message in an atomic section. New. new: Cleanup. Put removed/renamed message count in add_files_state_t. new: Cleanup. De-duplicate file name removal code. Both new, but closely related to previous remove_filename patch. new: Synchronize maildir flags eagerly. New, but very closely related to previous patch of the same name. This patch is simpler now because of the previous two cleanups. new: Wrap adding and removing messages in atomic sections. Rebased and added an atomic section around removal. lib: Improve notmuch_database_{add,remove}_message documentation. New. Ultimately, I still think the existing removal API is weird because it forces you to do things like lookup a message by file name just in case you need that message object after removal tells you that it didn't actually remove the message. But I don't know what to do about it that isn't equally weird.