1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
diff -ur nano-1.3.11/src/files.c nano-1.3.11-fixed/src/files.c
--- nano-1.3.11/src/files.c 2006-02-24 14:38:20.000000000 -0500
+++ nano-1.3.11-fixed/src/files.c 2006-05-18 08:59:47.000000000 -0400
@@ -1336,7 +1336,10 @@
statusbar(_("Error reading %s: %s"), realname,
strerror(errno));
beep();
- goto cleanup_and_exit;
+ /* 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;
}
}
@@ -1375,8 +1378,10 @@
_("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 +1403,9 @@
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
@@ -1414,7 +1420,6 @@
openfile->current_stat->st_uid,
openfile->current_stat->st_gid) == -1 ||
utime(backupname, &filetime) == -1) {
- free(backupname);
if (copy_status == -1) {
statusbar(_("Error reading %s: %s"), realname,
strerror(errno));
@@ -1422,11 +1427,15 @@
} else
statusbar(_("Error writing %s: %s"), backupname,
strerror(errno));
- 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
@@ -1454,6 +1463,17 @@
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) {
|