diff options
| author | David Bremner <david@tethera.net> | 2021-02-17 11:26:15 -0400 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-03-20 07:53:02 -0300 |
| commit | 4e209ca99ac8084a357c6fc8d7773f6207cfa16d (patch) | |
| tree | 5b99f0a0e79aa7a06d28d6ffa08b98bfd125bb14 /notmuch-new.c | |
| parent | a7873df331bcd53dd1bc8da95c4279163437cc13 (diff) | |
CLI/new: use configuration variable for backup directory
The stat is essentially replaced by the mkdir for error detection
purposes. This changes the default location for backups to make
things tidier, even in non-split configurations. Hopefully there is
not too many user scripts relying on the previous location.
Because the default location may not exist, replace the use of stat
for error detection with a call to mkdir.
Diffstat (limited to 'notmuch-new.c')
| -rw-r--r-- | notmuch-new.c | 18 |
1 files changed, 6 insertions, 12 deletions
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, |
