X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;h=ddf42c140802225078dce5a7316609404a439930;hp=82acf695353e614e97c1afc91a079f54d20a95f9;hb=0bb1f26a268c357b2aa1e6a704eb3a3fa695fa32;hpb=e8ec38c25afefacff8c2adb6e4f9e53df9870746 diff --git a/notmuch-new.c b/notmuch-new.c index 82acf695..ddf42c14 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -923,6 +923,7 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) notmuch_bool_t timer_is_active = FALSE; notmuch_bool_t no_hooks = FALSE; notmuch_bool_t quiet = FALSE, verbose = FALSE; + notmuch_status_t status; add_files_state.verbosity = VERBOSITY_NORMAL; add_files_state.debug = FALSE; @@ -989,15 +990,48 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; if (notmuch_database_needs_upgrade (notmuch)) { - if (add_files_state.verbosity >= VERBOSITY_NORMAL) + time_t now = time (NULL); + struct tm *gm_time = gmtime (&now); + + /* since dump files are written atomically, the amount of + * harm from overwriting one within a second seems + * relatively small. */ + + const char *backup_name = + talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz", + dot_notmuch_path, + gm_time->tm_year + 1900, + gm_time->tm_mon + 1, + gm_time->tm_mday, + gm_time->tm_hour, + gm_time->tm_min, + gm_time->tm_sec); + + if (add_files_state.verbosity >= VERBOSITY_NORMAL) { printf ("Welcome to a new version of notmuch! Your database will now be upgraded.\n"); + printf ("This process is safe to interrupt.\n"); + printf ("Backing up tags to %s...\n", backup_name); + } + + if (notmuch_database_dump (notmuch, backup_name, "", + DUMP_FORMAT_BATCH_TAG, TRUE)) { + fprintf (stderr, "Backup failed. Aborting upgrade."); + return EXIT_FAILURE; + } + gettimeofday (&add_files_state.tv_start, NULL); - notmuch_database_upgrade (notmuch, - add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL, - &add_files_state); + status = notmuch_database_upgrade ( + notmuch, + add_files_state.verbosity >= VERBOSITY_NORMAL ? upgrade_print_progress : NULL, + &add_files_state); + if (status) { + printf ("Upgrade failed: %s\n", + notmuch_status_to_string (status)); + notmuch_database_destroy (notmuch); + return EXIT_FAILURE; + } if (add_files_state.verbosity >= VERBOSITY_NORMAL) - printf ("Your notmuch database has now been upgraded to database format version %u.\n", - notmuch_database_get_version (notmuch)); + printf ("Your notmuch database has now been upgraded.\n"); } add_files_state.total_files = 0; @@ -1064,7 +1098,6 @@ notmuch_new_command (notmuch_config_t *config, int argc, char *argv[]) } for (f = add_files_state.directory_mtimes->head; f && !interrupted; f = f->next) { - notmuch_status_t status; notmuch_directory_t *directory; status = notmuch_database_get_directory (notmuch, f->filename, &directory); if (status == NOTMUCH_STATUS_SUCCESS && directory) {