]> git.wh0rd.org Git - nano.git/commitdiff
simplify the previous fix; also, in write_file(), clarify the error
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Fri, 7 Apr 2006 04:37:14 +0000 (04:37 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Fri, 7 Apr 2006 04:37:14 +0000 (04:37 +0000)
message when writing a temporary file for prepending fails

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

ChangeLog
src/files.c

index 8e22a09681071e58619c0fb2fa1960ce5f3422a4..32b1a1b61ce4f177ba682ce2c693cd3909775c59 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -24,6 +24,8 @@ CVS code -
          save the original file, if possible, since that's better than
          saving nothing. (DLR, problem found by Bill Marcum, solution
          suggested by Jordi)
+       - Clarify the error message when writing a temporary file for
+         prepending fails. (DLR)
 - rcfile.c:
   parse_argument()
        - Rename variable ptr_bak to ptr_save, for consistency. (DLR)
index d42b8ac7aa08ca4952d9ed556f3846af09fdd3b0..dd8c2a54cf992a662a4f8032763be403076b413a 100644 (file)
@@ -1336,15 +1336,10 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
                statusbar(_("Error reading %s: %s"), realname,
                        strerror(errno));
                beep();
-               /* If we can't read from the original file, and we're
-                * prepending, get out, since we won't be able to save
-                * either the backup or the original file.  If we're not
-                * prepending, go on, since only saving the original
-                * file is better than saving nothing. */
-               if (append == PREPEND)
-                   goto cleanup_and_exit;
-               else
-                   goto skip_backup;
+               /* If we can't read from the original file, go on, since
+                * only saving the original file is better than saving
+                * nothing. */
+               goto skip_backup;
            }
        }
 
@@ -1468,10 +1463,21 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
        int fd_source;
        FILE *f_source = NULL;
 
+       if (f == NULL) {
+           f = fopen(realname, "rb");
+
+           if (f == NULL) {
+               statusbar(_("Error reading %s: %s"), realname,
+                       strerror(errno));
+               beep();
+               goto cleanup_and_exit;
+           }
+       }
+
        tempname = safe_tempfile(&f);
 
        if (tempname == NULL) {
-           statusbar(_("Prepending to %s failed: %s"), realname,
+           statusbar(_("Could not create temp file: %s"),
                strerror(errno));
            goto cleanup_and_exit;
        }