tweaks: rename a function, to let it make more sense

Further, slightly reword an error message so it is appropriate also
when an out-of-bounds file is specified on the command line.
master
Benno Schulenberg 2017-08-12 15:52:07 +02:00
parent dd88842d5a
commit ec20e3a7a8
3 changed files with 11 additions and 13 deletions

View File

@ -248,7 +248,7 @@ char *do_browser(char *path)
}
#ifndef DISABLE_OPERATINGDIR
if (check_operating_dir(path, FALSE)) {
if (outside_of_confinement(path, FALSE)) {
/* TRANSLATORS: This refers to the confining effect of the
* option --operatingdir, not of --restricted. */
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
@ -281,7 +281,7 @@ char *do_browser(char *path)
/* Note: The selected file can be outside the operating
* directory if it's ".." or if it's a symlink to a
* directory outside the operating directory. */
if (check_operating_dir(filelist[selected], FALSE)) {
if (outside_of_confinement(filelist[selected], FALSE)) {
statusline(ALERT, _("Can't go outside of %s"), operating_dir);
continue;
}
@ -379,7 +379,7 @@ char *do_browse_from(const char *inpath)
#ifndef DISABLE_OPERATINGDIR
/* If the resulting path isn't in the operating directory, use
* the operating directory instead. */
if (check_operating_dir(path, FALSE))
if (outside_of_confinement(path, FALSE))
path = mallocstrcpy(path, operating_dir);
#endif

View File

@ -431,8 +431,8 @@ bool open_buffer(const char *filename, bool undoable)
as_an_at = FALSE;
#ifndef DISABLE_OPERATINGDIR
if (check_operating_dir(filename, FALSE)) {
statusline(ALERT, _("Can't insert file from outside of %s"),
if (outside_of_confinement(filename, FALSE)) {
statusline(ALERT, _("Can't read file from outside of %s"),
operating_dir);
return FALSE;
}
@ -1424,7 +1424,7 @@ void init_operating_dir(void)
* if we are, or TRUE otherwise. If allow_tabcomp is TRUE, allow
* incomplete names that would be matches for the operating directory,
* so that tab completion will work. */
bool check_operating_dir(const char *currpath, bool allow_tabcomp)
bool outside_of_confinement(const char *currpath, bool allow_tabcomp)
{
char *fullpath;
bool retval = FALSE;
@ -1583,7 +1583,7 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
#ifndef DISABLE_OPERATINGDIR
/* If we're writing a temporary file, we're probably going outside
* the operating directory, so skip the operating directory test. */
if (!tmp && check_operating_dir(realname, FALSE)) {
if (!tmp && outside_of_confinement(realname, FALSE)) {
statusline(ALERT, _("Can't write outside of %s"), operating_dir);
goto cleanup_and_exit;
}
@ -2437,7 +2437,7 @@ char **username_tab_completion(const char *buf, size_t *num_matches,
#ifndef DISABLE_OPERATINGDIR
/* ...unless the match exists outside the operating
* directory, in which case just go to the next match. */
if (check_operating_dir(userdata->pw_dir, TRUE))
if (outside_of_confinement(userdata->pw_dir, TRUE))
continue;
#endif
@ -2523,14 +2523,12 @@ char **cwd_tab_completion(const char *buf, bool allow_files, size_t
#ifndef DISABLE_OPERATINGDIR
/* ...unless the match exists outside the operating
* directory, in which case just go to the next match. */
if (check_operating_dir(tmp, TRUE))
skip_match = TRUE;
skip_match = outside_of_confinement(tmp, TRUE);
#endif
/* ...or unless the match isn't a directory and allow_files
* isn't set, in which case just go to the next match. */
if (!allow_files && !is_dir(tmp))
skip_match = TRUE;
skip_match = skip_match || (!allow_files && !is_dir(tmp));
free(tmp);

View File

@ -283,7 +283,7 @@ char *get_full_path(const char *origpath);
char *safe_tempfile(FILE **f);
#ifndef DISABLE_OPERATINGDIR
void init_operating_dir(void);
bool check_operating_dir(const char *currpath, bool allow_tabcomp);
bool outside_of_confinement(const char *currpath, bool allow_tabcomp);
#endif
#ifndef NANO_TINY
void init_backup_dir(void);