]> git.wh0rd.org Git - nano.git/commitdiff
in write_file(), if we can't save the backup file for some reason, at
authorDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 6 Apr 2006 05:18:23 +0000 (05:18 +0000)
committerDavid Lawrence Ramsey <pooka109@gmail.com>
Thu, 6 Apr 2006 05:18:23 +0000 (05:18 +0000)
least save the original file, if possible, since that's better than
saving nothing

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

ChangeLog
src/files.c

index 5f6fc86737aa55fbd0d5f04b2851d7f548781b33..dac25e882fe6f7d74036651bad6173e0d284256f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -14,6 +14,9 @@ CVS code -
   write_file()
        - Don't free backupname before displaying it in a statusbar error
          message. (DLR, found by Bill Marcum)
+       - If we can't save the backup file for some reason, at least
+         save the original file, if possible, since that's better than
+         saving nothing. (DLR, suggested by Jordi)
 - rcfile.c:
   parse_argument()
        - Rename variable ptr_bak to ptr_save, for consistency. (DLR)
index 2a0fda55039b572d1f61c70a7b9d57b10d9e0d62..00168d5fde8f903a35ea4864523bc8e277f4ee76 100644 (file)
@@ -1336,6 +1336,8 @@ 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 open the original file, we won't be able
+                * to save it, so get out. */
                goto cleanup_and_exit;
            }
        }
@@ -1375,8 +1377,10 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
                    _("Too many backup files?"));
                free(backuptemp);
                free(backupname);
-               fclose(f);
-               goto cleanup_and_exit;
+               /* If we can't write to the backup, go on, since only
+                * saving the original file is better than saving
+                * nothing. */
+               goto skip_backup;
            } else {
                free(backupname);
                backupname = backuptemp;
@@ -1398,8 +1402,9 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
            free(backupname);
            if (backup_file != NULL)
                fclose(backup_file);
-           fclose(f);
-           goto cleanup_and_exit;
+           /* If we can't write to the backup, go on, since only saving
+            * the original file is better than saving nothing. */
+           goto skip_backup;
        }
 
 #ifdef DEBUG
@@ -1421,12 +1426,15 @@ int write_file(const char *name, FILE *f_open, bool tmp, append_type
            } else
                statusbar(_("Error writing %s: %s"), backupname,
                        strerror(errno));
-           free(backupname);
-           goto cleanup_and_exit;
+           /* If we can't read from or write to the backup, go on,
+            * since only saving the original file is better than saving
+            * nothing. */
        }
 
        free(backupname);
     }
+
+  skip_backup:
 #endif /* !NANO_TINY */
 
     /* If NOFOLLOW_SYMLINKS is set and the file is a link, we aren't