[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Nano-devel] Using nano as your crontab editor
From: |
David Lawrence Ramsey |
Subject: |
Re: [Nano-devel] Using nano as your crontab editor |
Date: |
Wed, 05 Apr 2006 11:40:16 -0400 |
User-agent: |
Thunderbird 1.5 (X11/20051201) |
Jordi Mallach wrote:
<snip>
> Thanks for the patch. Regarding the behaviour, I think we need to
> consider, afaict editing a crontab with that option enabled isn't
> possible, as you just can't save it.
Definitely; I missed that.
> Shouldn't nano give up on saving a backup file if the directory where
> it needs to be written is not writable? This should only happen in
> special cases like crontab, where you use a suid binary to edit in a
> restricted area.
How about the attached patch? With it applied, if saving a backup
fails, nano tries to at least save the original file whenever possible,
on the principle that saving one file is better than saving none.
(Note: it won't apply to 1.3.11 unless you apply the last patch to
1.3.11 first.)
diff -ur nano/src/files.c nano-fixed/src/files.c
--- nano/src/files.c 2006-04-05 11:05:05.000000000 -0400
+++ nano-fixed/src/files.c 2006-04-05 11:30:55.000000000 -0400
@@ -1336,6 +1336,8 @@
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 @@
_("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 @@
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 @@
} 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