+ removed_files = 0;
+ renamed_files = 0;
+ gettimeofday (&tv_start, NULL);
+ for (f = add_files_state.removed_files->head; f; f = f->next) {
+ status = notmuch_database_remove_message (notmuch, f->filename);
+ if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID)
+ renamed_files++;
+ else
+ removed_files++;
+ if (do_print_progress) {
+ do_print_progress = 0;
+ generic_print_progress ("Cleaned up", "messages",
+ tv_start, removed_files + renamed_files,
+ add_files_state.removed_files->count);
+ }
+ }
+
+ gettimeofday (&tv_start, NULL);
+ for (f = add_files_state.removed_directories->head, i = 0; f; f = f->next, i++) {
+ _remove_directory (ctx, notmuch, f->filename,
+ &renamed_files, &removed_files);
+ if (do_print_progress) {
+ do_print_progress = 0;
+ generic_print_progress ("Cleaned up", "directories",
+ tv_start, i,
+ add_files_state.removed_directories->count);
+ }
+ }
+
+ talloc_free (add_files_state.removed_files);
+ talloc_free (add_files_state.removed_directories);
+
+ /* Now that removals are done (hence the database is aware of all
+ * renames), we can synchronize maildir_flags to tags for all
+ * messages that had new filenames appear on this run. */
+ gettimeofday (&tv_start, NULL);
+ if (add_files_state.synchronize_flags) {
+ _filename_node_t *node;
+ notmuch_message_t *message;
+ for (node = add_files_state.message_ids_to_sync->head, i = 0;
+ node;
+ node = node->next, i++)
+ {
+ message = notmuch_database_find_message (notmuch, node->filename);
+ notmuch_message_maildir_flags_to_tags (message);
+ notmuch_message_destroy (message);
+ if (do_print_progress) {
+ do_print_progress = 0;
+ generic_print_progress (
+ "Synchronized tags for", "messages",
+ tv_start, i, add_files_state.message_ids_to_sync->count);
+ }
+ }
+ }
+
+ talloc_free (add_files_state.message_ids_to_sync);
+ add_files_state.message_ids_to_sync = NULL;
+
+ if (timer_is_active)
+ stop_progress_printing_timer ();
+