X-Git-Url: https://git.notmuchmail.org/git?p=notmuch;a=blobdiff_plain;f=notmuch-new.c;fp=notmuch-new.c;h=8e2bf4a84babba4fe80e6b2ce72c2e4c8a6cefa1;hp=4f29aa2a513fea93c7a0973b2645349a5678d24e;hb=4e209ca99ac8084a357c6fc8d7773f6207cfa16d;hpb=a7873df331bcd53dd1bc8da95c4279163437cc13 diff --git a/notmuch-new.c b/notmuch-new.c index 4f29aa2a..8e2bf4a8 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1051,28 +1051,22 @@ _maybe_upgrade (notmuch_database_t *notmuch, add_files_state_t *state) if (notmuch_database_needs_upgrade (notmuch)) { time_t now = time (NULL); struct tm *gm_time = gmtime (&now); - struct stat st; int err; notmuch_status_t status; - char *dot_notmuch_path = talloc_asprintf (notmuch, "%s/%s", state->db_path, ".notmuch"); - + const char *backup_dir = notmuch_config_get (notmuch, NOTMUCH_CONFIG_BACKUP_DIR); const char *backup_name; - err = stat (dot_notmuch_path, &st); - if (err) { - if (errno == ENOENT) { - dot_notmuch_path = NULL; - } else { - fprintf (stderr, "Failed to stat %s: %s\n", dot_notmuch_path, strerror (errno)); - return EXIT_FAILURE; - } + err = mkdir (backup_dir, 0755); + if (err && errno != EEXIST) { + fprintf (stderr, "Failed to create %s: %s\n", backup_dir, strerror (errno)); + return EXIT_FAILURE; } /* since dump files are written atomically, the amount of * harm from overwriting one within a second seems * relatively small. */ backup_name = talloc_asprintf (notmuch, "%s/dump-%04d%02d%02dT%02d%02d%02d.gz", - dot_notmuch_path ? dot_notmuch_path : state->db_path, + backup_dir, gm_time->tm_year + 1900, gm_time->tm_mon + 1, gm_time->tm_mday,