+ }
+}
+
+static void
+upgrade_print_progress (void *closure,
+ double progress)
+{
+ add_files_state_t *state = closure;
+
+ printf ("Upgrading database: %.2f%% complete", progress * 100.0);
+
+ if (progress > 0) {
+ struct timeval tv_now;
+ double elapsed, time_remaining;
+
+ gettimeofday (&tv_now, NULL);
+
+ elapsed = notmuch_time_elapsed (state->tv_start, tv_now);
+ time_remaining = (elapsed / progress) * (1.0 - progress);
+ printf (" (");
+ notmuch_time_print_formatted_seconds (time_remaining);
+ printf (" remaining)");
+ }
+
+ printf (". \r");
+
+ fflush (stdout);
+}
+
+/* Remove one message filename from the database. */
+static notmuch_status_t
+remove_filename (notmuch_database_t *notmuch,
+ const char *path,
+ add_files_state_t *add_files_state)
+{
+ notmuch_status_t status;
+ notmuch_message_t *message;
+ status = notmuch_database_begin_atomic (notmuch);
+ if (status)
+ return status;
+ status = notmuch_database_find_message_by_filename (notmuch, path, &message);
+ if (status || message == NULL)
+ goto DONE;
+
+ status = notmuch_database_remove_message (notmuch, path);
+ if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) {
+ add_files_state->renamed_messages++;
+ if (add_files_state->synchronize_flags == TRUE)
+ notmuch_message_maildir_flags_to_tags (message);
+ status = NOTMUCH_STATUS_SUCCESS;
+ } else if (status == NOTMUCH_STATUS_SUCCESS) {
+ add_files_state->removed_messages++;
+ }
+ notmuch_message_destroy (message);
+
+ DONE:
+ notmuch_database_end_atomic (notmuch);
+ return status;