]> git.wh0rd.org Git - nano.git/commitdiff
Avoiding a possibly erroneous message, because failing to delete
authorBenno Schulenberg <bensberg@justemail.net>
Tue, 11 Aug 2015 17:43:08 +0000 (17:43 +0000)
committerBenno Schulenberg <bensberg@justemail.net>
Tue, 11 Aug 2015 17:43:08 +0000 (17:43 +0000)
the temporary file does not mean that copying failed.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5353 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
src/files.c

index 53fca6fee598092d847aeaf45d95d6c6fcfdbbc5..a3b769b522aa7ec147e6ac390d5a51d04990ee55 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2015-08-11  Benno Schulenberg  <bensberg@justemail.net>
        * 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-09  Benno Schulenberg  <bensberg@justemail.net>
        * src/global.c, src/help.c (help_init), src/nano.c (do_toggle, main),
index 5f95ae32d9ce65aa3b65b1771a57d919d114ffdb..c93ef39cc153d46958f7c2f199d10067a3ea64fb 100644 (file)
@@ -1719,7 +1719,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);
 
@@ -2122,11 +2122,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));