]> git.notmuchmail.org Git - notmuch/commitdiff
new: Wrap adding and removing messages in atomic sections.
authorAustin Clements <amdragon@mit.edu>
Sat, 29 Jan 2011 16:25:56 +0000 (11:25 -0500)
committerDavid Bremner <bremner@debian.org>
Sat, 24 Sep 2011 23:00:29 +0000 (20:00 -0300)
This addresses atomicity of tag synchronization, the last atomicity
problems in notmuch new.  Each message add or remove is wrapped in its
own atomic section, so interrupting notmuch new doesn't lose progress.

notmuch-new.c
test/atomicity

index 598a2083ffaec689285878a6a4b873d8d6f4b245..e79593cd092dd3345a8bac182234833ecfc92333 100644 (file)
@@ -450,6 +450,12 @@ add_files_recursive (notmuch_database_t *notmuch,
            fflush (stdout);
        }
 
            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 */
        status = notmuch_database_add_message (notmuch, next, &message);
        switch (status) {
        /* success */
@@ -490,6 +496,12 @@ add_files_recursive (notmuch_database_t *notmuch,
            goto DONE;
        }
 
            goto DONE;
        }
 
+       status = notmuch_database_end_atomic (notmuch);
+       if (status) {
+           ret = status;
+           goto DONE;
+       }
+
        if (message) {
            notmuch_message_destroy (message);
            message = NULL;
        if (message) {
            notmuch_message_destroy (message);
            message = NULL;
@@ -728,6 +740,9 @@ remove_filename (notmuch_database_t *notmuch,
 {
     notmuch_status_t status;
     notmuch_message_t *message;
 {
     notmuch_status_t status;
     notmuch_message_t *message;
+    status = notmuch_database_begin_atomic (notmuch);
+    if (status)
+       return status;
     message = notmuch_database_find_message_by_filename (notmuch, path);
     status = notmuch_database_remove_message (notmuch, path);
     if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
     message = notmuch_database_find_message_by_filename (notmuch, path);
     status = notmuch_database_remove_message (notmuch, path);
     if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
@@ -737,6 +752,7 @@ remove_filename (notmuch_database_t *notmuch,
     } else
        add_files_state->removed_messages++;
     notmuch_message_destroy (message);
     } else
        add_files_state->removed_messages++;
     notmuch_message_destroy (message);
+    notmuch_database_end_atomic (notmuch);
     return status;
 }
 
     return status;
 }
 
index 88b39587b355878858ec95e11b3277bbee8680c9..eeff6be926604d9d16fe820642ac09c761dff904 100755 (executable)
@@ -94,7 +94,6 @@ for ((i = 0; i < $outcount; i++)); do
 done
 
 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
 done
 
 test_begin_subtest '"notmuch new" is idempotent under arbitrary aborts'
-test_subtest_known_broken
 test_expect_equal_file GDB searchall expectall
 
 test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10"
 test_expect_equal_file GDB searchall expectall
 
 test_expect_success GDB "detected $outcount>10 abort points" "test $outcount -gt 10"