X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=lib%2Fdatabase.cc;h=9299c8d52e3c3e0a93c6906a64956236175abb60;hb=51c3c0b2d27c8d0ba8e1ae242fd907c59f82d992;hp=f8b95bc46f5fcacf61839c30b4b1cf17a124c9f4;hpb=7a8046ced8c0e61ddd0ff463cfc17ed63e6edad3;p=obsolete%2Fnotmuch-old diff --git a/lib/database.cc b/lib/database.cc index f8b95bc4..9299c8d5 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1601,7 +1601,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, { notmuch_message_file_t *message_file; notmuch_message_t *message = NULL; - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, ret2; notmuch_private_status_t private_status; const char *date, *header; @@ -1619,6 +1619,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (message_file == NULL) return NOTMUCH_STATUS_FILE_ERROR; + /* Adding a message may change many documents. Do this all + * atomically. */ + ret = notmuch_database_begin_atomic (notmuch); + if (ret) + goto DONE; + notmuch_message_file_restrict_headers (message_file, "date", "from", @@ -1740,6 +1746,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (message_file) notmuch_message_file_close (message_file); + ret2 = notmuch_database_end_atomic (notmuch); + if ((ret == NOTMUCH_STATUS_SUCCESS || + ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) && + ret2 != NOTMUCH_STATUS_SUCCESS) + ret = ret2; + return ret; }