From 2623f39c7b2d2f3e0e2fe8cba1628c778a7d87b9 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 17 Jul 2020 16:29:10 +0200 Subject: [PATCH] backup: when rereading the original file fails, ask the user what to do Rereading is unlikely to fail, but *if* it fails, maybe there is a serious problem and the user wants to try and fix it before saving the buffer and thus overwriting the original file. --- src/files.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/files.c b/src/files.c index 2876038a..9cc58c76 100644 --- a/src/files.c +++ b/src/files.c @@ -1655,23 +1655,19 @@ bool make_backup_of(char *realname) original = fopen(realname, "rb"); - /* If we can't read from the original file, go on, since saving - * only the current buffer is better than saving nothing. */ if (original == NULL) { - statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); + warn_and_briefly_pause(_("Cannot read original file")); fclose(backup_file); - free(backupname); - return TRUE; + goto failure; } /* Copy the existing file to the backup. */ verdict = copy_file(original, backup_file, FALSE); if (verdict < 0) { - statusline(ALERT, _("Error reading %s: %s"), realname, strerror(errno)); + warn_and_briefly_pause(_("Cannot read original file")); fclose(backup_file); - free(backupname); - return FALSE; + goto failure; } else if (verdict > 0) { fclose(backup_file); goto problem; @@ -1714,6 +1710,7 @@ bool make_backup_of(char *realname) } warn_and_briefly_pause(_("Cannot make backup")); + failure: warn_and_briefly_pause(strerror(errno)); currmenu = MMOST;