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.
master
David Lawrence Ramsey 2016-11-27 15:01:54 -06:00 committed by Benno Schulenberg
parent d48071b2b2
commit e4d452424b
4 changed files with 17 additions and 18 deletions

View File

@ -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

View File

@ -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.) "));

View File

@ -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);

View File

@ -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. */