[PATCH 07/10] new: Use the new filename removal API.

Austin Clements amdragon at MIT.EDU
Thu Feb 17 23:58:57 PST 2011


This paves the way for eager tag synchronization and correct removal
atomicity.
---
 notmuch-new.c |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/notmuch-new.c b/notmuch-new.c
index 65682d8..56fe7b0 100644
--- a/notmuch-new.c
+++ b/notmuch-new.c
@@ -691,6 +691,27 @@ upgrade_print_progress (void *closure,
     fflush (stdout);
 }
 
+/* Remove one message filename from the database. */
+static notmuch_status_t
+remove_file (notmuch_database_t *notmuch,
+	     const char *path,
+	     int *renamed_files,
+	     int *removed_files)
+{
+    notmuch_status_t status;
+    notmuch_message_t *message;
+    message = notmuch_database_find_message_by_filename (notmuch, path);
+    if (!message)
+	return NOTMUCH_STATUS_SUCCESS;
+    status = notmuch_message_remove_filename (message, path);
+    if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
+	(*renamed_files)++;
+    else
+	(*removed_files)++;
+    notmuch_message_destroy (message);
+    return status;
+}
+
 /* Recursively remove all filenames from the database referring to
  * 'path' (or to any of its children). */
 static void
@@ -702,7 +723,6 @@ _remove_directory (void *ctx,
 {
     notmuch_directory_t *directory;
     notmuch_filenames_t *files, *subdirs;
-    notmuch_status_t status;
     char *absolute;
 
     directory = notmuch_database_get_directory (notmuch, path);
@@ -713,11 +733,7 @@ _remove_directory (void *ctx,
     {
 	absolute = talloc_asprintf (ctx, "%s/%s", path,
 				    notmuch_filenames_get (files));
-	status = notmuch_database_remove_message (notmuch, absolute);
-	if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
-	    *renamed_files = *renamed_files + 1;
-	else
-	    *removed_files = *removed_files + 1;
+	remove_file (notmuch, absolute, renamed_files, removed_files);
 	talloc_free (absolute);
     }
 
@@ -749,7 +765,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     struct sigaction action;
     _filename_node_t *f;
     int renamed_files, removed_files;
-    notmuch_status_t status;
     int i;
     notmuch_bool_t timer_is_active = FALSE;
 
@@ -839,11 +854,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     renamed_files = 0;
     gettimeofday (&tv_start, NULL);
     for (f = add_files_state.removed_files->head; f && !interrupted; f = f->next) {
-	status = notmuch_database_remove_message (notmuch, f->filename);
-	if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
-	    renamed_files++;
-	else
-	    removed_files++;
+	remove_file (notmuch, f->filename, &renamed_files, &removed_files);
 	if (do_print_progress) {
 	    do_print_progress = 0;
 	    generic_print_progress ("Cleaned up", "messages",
-- 
1.7.2.3



More information about the notmuch mailing list