X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=55c3dc1d8d75c8873fb64308d2e72b5d63cb661e;hp=739ca1189a8834bb46c540a99039b1f30f1195c3;hb=5fe5e802ab3101a375ec1262770955904e169e47;hpb=21f8fd6967c3ef8e726652bbd6944e29975508b5 diff --git a/notmuch-new.c b/notmuch-new.c index 739ca118..55c3dc1d 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -616,6 +616,28 @@ count_files (const char *path, int *count) free (fs_entries); } +static void +upgrade_print_progress (void *closure, + unsigned int count, + unsigned int total) +{ + add_files_state_t *state = closure; + struct timeval tv_now; + double elapsed_overall, rate_overall, time_remaining; + + gettimeofday (&tv_now, NULL); + + elapsed_overall = notmuch_time_elapsed (state->tv_start, tv_now); + rate_overall = count / elapsed_overall; + time_remaining = ((total - count) / rate_overall); + + printf ("Upgraded %d of %d messages (", count, total); + notmuch_time_print_formatted_seconds (time_remaining); + printf (" remaining). \r"); + + fflush (stdout); +} + /* Recursively remove all filenames from the database referring to * 'path' (or to any of its children). */ static void @@ -689,13 +711,6 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) } } - /* Setup our handler for SIGINT */ - memset (&action, 0, sizeof (struct sigaction)); - action.sa_handler = handle_sigint; - sigemptyset (&action.sa_mask); - action.sa_flags = SA_RESTART; - sigaction (SIGINT, &action, NULL); - config = notmuch_config_open (ctx, NULL, NULL); if (config == NULL) return 1; @@ -718,12 +733,33 @@ notmuch_new_command (void *ctx, int argc, char *argv[]) } else { notmuch = notmuch_database_open (db_path, NOTMUCH_DATABASE_MODE_READ_WRITE); + if (notmuch == NULL) + return 1; + + if (notmuch_database_needs_upgrade (notmuch)) { + printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n"); + gettimeofday (&add_files_state.tv_start, NULL); + notmuch_database_upgrade (notmuch, upgrade_print_progress, + &add_files_state); + printf ("Your notmuch database has now been upgraded to database format version %u.\n", + notmuch_database_get_version (notmuch)); + } + add_files_state.total_files = 0; } if (notmuch == NULL) return 1; + /* Setup our handler for SIGINT. We do this after having + * potentially done a database upgrade we this interrupt handler + * won't support. */ + memset (&action, 0, sizeof (struct sigaction)); + action.sa_handler = handle_sigint; + sigemptyset (&action.sa_mask); + action.sa_flags = SA_RESTART; + sigaction (SIGINT, &action, NULL); + talloc_free (dot_notmuch_path); dot_notmuch_path = NULL;