From e4d452424bbd702e7d6251cf322bbd1ecda3bc8c Mon Sep 17 00:00:00 2001 From: David Lawrence Ramsey Date: Sun, 27 Nov 2016 15:01:54 -0600 Subject: [PATCH] files: give feedback when restricted mode prevents overwriting a file Achieve this by reusing the code that gives feedback when trying to save a buffer while using --tempfile and the file has no name yet. This fixes https://savannah.gnu.org/bugs/?48622. --- src/files.c | 5 ++++- src/nano.c | 17 +---------------- src/proto.h | 2 +- src/winio.c | 11 +++++++++++ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/files.c b/src/files.c index c105db15..6b575391 100644 --- a/src/files.c +++ b/src/files.c @@ -2370,8 +2370,11 @@ int do_writeout(bool exiting) * of the current file if it has one, because that * would allow reading from or writing to files not * specified on the command line. */ - if (ISSET(RESTRICTED)) + if (ISSET(RESTRICTED)) { + warn_and_shortly_pause(_("File exists -- " + "cannot overwrite")); continue; + } if (!maychange) { #ifndef NANO_TINY diff --git a/src/nano.c b/src/nano.c index 573f8219..fdf92564 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1058,21 +1058,6 @@ void version(void) printf("\n"); } -/* Indicate that the current file has no name, in a way that gets the - * user's attention. This is used when trying to save a file with no - * name with the TEMP_FILE flag set, just before the filename prompt. */ -void no_current_file_name_warning(void) -{ - /* Warn that the current file has no name. */ - statusbar(_("No file name")); - beep(); - - /* Ensure that we see the warning. */ - napms(1800); - - curs_set(1); -} - /* If the current file buffer has been modified, and the TEMP_FILE flag * isn't set, ask whether or not to save the file buffer. If the * TEMP_FILE flag is set and the current file has a name, save it @@ -1096,7 +1081,7 @@ void do_exit(void) /* If the TEMP_FILE flag is set, and the current file doesn't * have a name, warn the user before prompting for a name. */ if (ISSET(TEMP_FILE)) - no_current_file_name_warning(); + warn_and_shortly_pause(_("No file name")); i = do_yesno_prompt(FALSE, _("Save modified buffer? " "(Answering \"No\" will DISCARD changes.) ")); diff --git a/src/proto.h b/src/proto.h index f3c9b0ee..ead972e5 100644 --- a/src/proto.h +++ b/src/proto.h @@ -456,7 +456,6 @@ void print_opt_full(const char *shortflag , const char *desc); void usage(void); void version(void); -void no_current_file_name_warning(void); void do_exit(void); void close_and_go(void); void signal_init(void); @@ -739,6 +738,7 @@ char *display_string(const char *buf, size_t start_col, size_t span, void titlebar(const char *path); extern void set_modified(void); void statusbar(const char *msg); +void warn_and_shortly_pause(const char *msg); void statusline(message_type importance, const char *msg, ...); void bottombars(int menu); void onekey(const char *keystroke, const char *desc, int length); diff --git a/src/winio.c b/src/winio.c index 38dfb1ce..8273af56 100644 --- a/src/winio.c +++ b/src/winio.c @@ -2070,6 +2070,17 @@ void statusbar(const char *msg) statusline(HUSH, msg); } +/* Warn the user on the statusbar and pause for a moment, so that the + * message can be noticed and read. */ +void warn_and_shortly_pause(const char *msg) +{ + statusbar(msg); + beep(); + napms(1800); + + curs_set(1); +} + /* Display a message on the statusbar, and set suppress_cursorpos to * TRUE, so that the message won't be immediately overwritten if * constant cursor position display is on. */