summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7a8046c)
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.
{
notmuch_message_file_t *message_file;
notmuch_message_t *message = NULL;
{
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;
notmuch_private_status_t private_status;
const char *date, *header;
if (message_file == NULL)
return NOTMUCH_STATUS_FILE_ERROR;
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",
notmuch_message_file_restrict_headers (message_file,
"date",
"from",
if (message_file)
notmuch_message_file_close (message_file);
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;
+