commit eddd8963e73080324b866430b2a8be3f73b4c93a
parent 160f07babae5849dba58d7fd6e24f3a6656285b4
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Fri, 29 May 2020 10:18:25 +0200
files: ask the user whether to proceed every time a backup fails
If the user answered "No" or "Cancel" the first time, they should
be allowed to answer "Yes" the next time -- possibly after fixing
the necessary permissions in another terminal.
This fixes https://savannah.gnu.org/bugs/?58442.
Bug existed since version 2.3.0, commit 3d411188.
Diffstat:
1 file changed, 5 insertions(+), 14 deletions(-)
diff --git a/src/files.c b/src/files.c
@@ -1477,19 +1477,10 @@ bool outside_of_confinement(const char *currpath, bool allow_tabcomp)
#ifndef NANO_TINY
/* Although this sucks, it sucks less than having a single 'my system is
* messed up and I'm blanket allowing insecure file writing operations'. */
-bool prompt_failed_backupwrite(const char *filename)
+bool user_wants_to_proceed(void)
{
- static char *prevfile = NULL;
- /* The last filename we were passed, so we don't keep asking this. */
- static int choice = 0;
-
- if (prevfile == NULL || strcmp(filename, prevfile)) {
- choice = do_yesno_prompt(FALSE, _("Failed to write backup file; "
- "continue saving? (Say N if unsure.) "));
- prevfile = mallocstrcpy(prevfile, filename);
- }
-
- return (choice == 1);
+ return (do_yesno_prompt(FALSE, _("Cannot make backup; "
+ "continue and save actual file? ")) == 1);
}
/* Transform the specified backup directory to an absolute path,
@@ -1648,7 +1639,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
/* Now first try to delete an existing backup file. */
if (unlink(backupname) < 0 && errno != ENOENT && !ISSET(INSECURE_BACKUP)) {
- if (prompt_failed_backupwrite(backupname))
+ if (user_wants_to_proceed())
goto skip_backup;
statusline(HUSH, _("Error writing backup file %s: %s"),
backupname, strerror(errno));
@@ -1693,7 +1684,7 @@ bool write_file(const char *name, FILE *thefile, bool tmp,
goto cleanup_and_exit;
} else if (verdict > 0) {
fclose(backup_file);
- if (prompt_failed_backupwrite(backupname))
+ if (user_wants_to_proceed())
goto skip_backup;
statusline(HUSH, _("Error writing backup file %s: %s"),
backupname, strerror(errno));