From 512b0fd32d199ae45bc857fe66c3752f6dd13af8 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 29 May 2020 11:32:35 +0200 Subject: [PATCH] files: take into account that also closing a backup file can fail Only when fclose() is called, does the data get flushed out to disk, and maybe only then the system realizes that there is no space left on the device, as Chris noted in: https://savannah.gnu.org/bugs/?24000. --- src/files.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/files.c b/src/files.c index 57439840..8eb8c80e 100644 --- a/src/files.c +++ b/src/files.c @@ -1701,7 +1701,16 @@ bool write_file(const char *name, FILE *thefile, bool tmp, * Failure is unimportant: saving the file apparently worked. */ IGNORE_CALL_RESULT(futimens(backup_fd, filetime)); - fclose(backup_file); + if (fclose(backup_file) != 0) { + warn_and_briefly_pause(_("Cannot write backup")); + if (user_wants_to_proceed()) + goto skip_backup; + statusline(HUSH, _("Cannot write backup %s: %s"), + backupname, strerror(errno)); + free(backupname); + goto cleanup_and_exit; + } + free(backupname); }