[PATCH 10/10] new: Wrap adding a message in an atomic section.

Subject: [PATCH 10/10] new: Wrap adding a message in an atomic section.

Date: Fri, 18 Feb 2011 02:59:00 -0500

To: notmuch@notmuchmail.org

Cc: amdragon@mit.edu

From: Austin Clements


This prevents atomicity violations when adding new messages.  Each
message add is wrapped in its own atomic section, so interrupting
notmuch new doesn't loose progress.  Unlike in the remove case, adding
a message can modify more than one database document, necessitating
full transactions.
---
 notmuch-new.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 767722a..880f31a 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -424,6 +424,12 @@ add_files_recursive (notmuch_database_t *notmuch,
 	    fflush (stdout);
 	}
 
+	status = notmuch_database_begin_atomic (notmuch);
+	if (status) {
+	    ret = status;
+	    goto DONE;
+	}
+
 	status = notmuch_database_add_message (notmuch, next, &message);
 	switch (status) {
 	/* success */
@@ -463,6 +469,12 @@ add_files_recursive (notmuch_database_t *notmuch,
 	    goto DONE;
 	}
 
+	status = notmuch_database_end_atomic (notmuch);
+	if (status) {
+	    ret = status;
+	    goto DONE;
+	}
+
 	if (message) {
 	    notmuch_message_destroy (message);
 	    message = NULL;
-- 
1.7.2.3


Thread: