mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 12:28:09 +01:00
lib: Wrap notmuch_database_add_message in an atomic section.
Adding a message may involve changes to multiple database documents, and thus needs to be done in a transaction. This makes add_message (and, I think, the whole library) atomicity-safe: library callers only needs to use atomic sections if they needs atomicity across multiple library calls.
This commit is contained in:
parent
7a8046ced8
commit
51c3c0b2d2
1 changed files with 13 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue