From 0e3472b1073c9bf4811e07e009500b10b04c6332 Mon Sep 17 00:00:00 2001 From: Chris Allegretta Date: Sun, 15 Nov 2015 06:47:43 +0000 Subject: [PATCH] Backport r5353 from trunk. git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_2_4_branch@5415 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 2 ++ src/files.c | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bbc4130..02975bcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,8 @@ 2015-08-11 Benno Schulenberg * src/files.c (write_file): Avoid calling copy_file() with a null pointer. Found with cppcheck. + * src/files.c (write_file): A failure to delete the temporary file + does not mean that it wasn't copied properly. 2015-08-08 Benno Schulenberg * src/winio.c (display_string): For some reason the reallocation done diff --git a/src/files.c b/src/files.c index 85bb006a..6081e4a1 100644 --- a/src/files.c +++ b/src/files.c @@ -1728,7 +1728,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type FILE *f = NULL; /* The actual file, realname, we are writing to. */ char *tempname = NULL; - /* The temp file name we write to on prepend. */ + /* The name of the temporary file we write to on prepend. */ assert(name != NULL); @@ -2135,11 +2135,13 @@ bool write_file(const char *name, FILE *f_open, bool tmp, append_type goto cleanup_and_exit; } - if (copy_file(f_source, f) == -1 || unlink(tempname) == -1) { + if (copy_file(f_source, f) == -1) { statusbar(_("Error writing %s: %s"), realname, strerror(errno)); goto cleanup_and_exit; } + + unlink(tempname); } else if (fclose(f) != 0) { statusbar(_("Error writing %s: %s"), realname, strerror(errno)); -- 2.39.5