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
parent
d48071b2b2
commit
e4d452424b
|
@ -2370,8 +2370,11 @@ int do_writeout(bool exiting)
|
||||||
* of the current file if it has one, because that
|
* of the current file if it has one, because that
|
||||||
* would allow reading from or writing to files not
|
* would allow reading from or writing to files not
|
||||||
* specified on the command line. */
|
* specified on the command line. */
|
||||||
if (ISSET(RESTRICTED))
|
if (ISSET(RESTRICTED)) {
|
||||||
|
warn_and_shortly_pause(_("File exists -- "
|
||||||
|
"cannot overwrite"));
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!maychange) {
|
if (!maychange) {
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
|
|
17
src/nano.c
17
src/nano.c
|
@ -1058,21 +1058,6 @@ void version(void)
|
||||||
printf("\n");
|
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
|
/* 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
|
* 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
|
* 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
|
/* If the TEMP_FILE flag is set, and the current file doesn't
|
||||||
* have a name, warn the user before prompting for a name. */
|
* have a name, warn the user before prompting for a name. */
|
||||||
if (ISSET(TEMP_FILE))
|
if (ISSET(TEMP_FILE))
|
||||||
no_current_file_name_warning();
|
warn_and_shortly_pause(_("No file name"));
|
||||||
|
|
||||||
i = do_yesno_prompt(FALSE, _("Save modified buffer? "
|
i = do_yesno_prompt(FALSE, _("Save modified buffer? "
|
||||||
"(Answering \"No\" will DISCARD changes.) "));
|
"(Answering \"No\" will DISCARD changes.) "));
|
||||||
|
|
|
@ -456,7 +456,6 @@ void print_opt_full(const char *shortflag
|
||||||
, const char *desc);
|
, const char *desc);
|
||||||
void usage(void);
|
void usage(void);
|
||||||
void version(void);
|
void version(void);
|
||||||
void no_current_file_name_warning(void);
|
|
||||||
void do_exit(void);
|
void do_exit(void);
|
||||||
void close_and_go(void);
|
void close_and_go(void);
|
||||||
void signal_init(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);
|
void titlebar(const char *path);
|
||||||
extern void set_modified(void);
|
extern void set_modified(void);
|
||||||
void statusbar(const char *msg);
|
void statusbar(const char *msg);
|
||||||
|
void warn_and_shortly_pause(const char *msg);
|
||||||
void statusline(message_type importance, const char *msg, ...);
|
void statusline(message_type importance, const char *msg, ...);
|
||||||
void bottombars(int menu);
|
void bottombars(int menu);
|
||||||
void onekey(const char *keystroke, const char *desc, int length);
|
void onekey(const char *keystroke, const char *desc, int length);
|
||||||
|
|
11
src/winio.c
11
src/winio.c
|
@ -2070,6 +2070,17 @@ void statusbar(const char *msg)
|
||||||
statusline(HUSH, 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
|
/* Display a message on the statusbar, and set suppress_cursorpos to
|
||||||
* TRUE, so that the message won't be immediately overwritten if
|
* TRUE, so that the message won't be immediately overwritten if
|
||||||
* constant cursor position display is on. */
|
* constant cursor position display is on. */
|
||||||
|
|
Loading…
Reference in New Issue