]> git.cworth.org Git - notmuch/blobdiff - notmuch-new.c
notmuch new: Print counts of deleted and renamed messages.
[notmuch] / notmuch-new.c
index f8fe66a3b153c58e2bb1e0652d97623853cd0576..ab1d12a6fd7dd8ea1a800fc30c4686c096ba62fe 100644 (file)
@@ -567,6 +567,8 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     char *dot_notmuch_path;
     struct sigaction action;
     _filename_node_t *f;
+    int renamed_files, removed_files;
+    notmuch_status_t status;
     int i;
 
     add_files_state.verbose = 0;
@@ -628,12 +630,39 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
 
     ret = add_files (notmuch, db_path, &add_files_state);
 
+    removed_files = 0;
+    renamed_files = 0;
     for (f = add_files_state.removed_files->head; f; f = f->next) {
-       printf ("Detected removed file: %s\n", f->filename);
+       status = notmuch_database_remove_message (notmuch, f->filename);
+       if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
+           renamed_files++;
+       else
+           removed_files++;
     }
 
     for (f = add_files_state.removed_directories->head; f; f = f->next) {
-       printf ("Detected removed directory: %s\n", f->filename);
+       notmuch_directory_t *directory;
+       notmuch_filenames_t *files;
+
+       directory = notmuch_database_get_directory (notmuch, f->filename);
+
+       for (files = notmuch_directory_get_child_files (directory);
+            notmuch_filenames_has_more (files);
+            notmuch_filenames_advance (files))
+       {
+           char *absolute;
+
+           absolute = talloc_asprintf (ctx, "%s/%s", f->filename,
+                                       notmuch_filenames_get (files));
+           status = notmuch_database_remove_message (notmuch, absolute);
+           if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
+               renamed_files++;
+           else
+               removed_files++;
+           talloc_free (absolute);
+       }
+
+       notmuch_directory_destroy (directory);
     }
 
     talloc_free (add_files_state.removed_files);
@@ -642,6 +671,7 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
     gettimeofday (&tv_now, NULL);
     elapsed = notmuch_time_elapsed (add_files_state.tv_start,
                                    tv_now);
+
     if (add_files_state.processed_files) {
        printf ("Processed %d %s in ", add_files_state.processed_files,
                add_files_state.processed_files == 1 ?
@@ -654,15 +684,30 @@ notmuch_new_command (void *ctx, int argc, char *argv[])
            printf (".                    \n");
        }
     }
+
     if (add_files_state.added_messages) {
-       printf ("Added %d new %s to the database.\n",
+       printf ("Added %d new %s to the database.",
                add_files_state.added_messages,
                add_files_state.added_messages == 1 ?
                "message" : "messages");
     } else {
-       printf ("No new mail.\n");
+       printf ("No new mail.");
+    }
+
+    if (removed_files) {
+       printf (" Removed %d %s.",
+               removed_files,
+               removed_files == 1 ? "message" : "messages");
     }
 
+    if (renamed_files) {
+       printf (" Detected %d file %s.",
+               renamed_files,
+               renamed_files == 1 ? "rename" : "renames");
+    }
+
+    printf ("\n");
+
     if (ret) {
        printf ("\nNote: At least one error was encountered: %s\n",
                notmuch_status_to_string (ret));