From 97df604299146dd0ddf4cb887097579e325d2041 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Tue, 21 Jun 2016 19:11:40 +0200 Subject: [PATCH] browser: don't appear to enter a directory when it is inaccessible This fixes https://savannah.gnu.org/bugs/?48286. --- src/browser.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/browser.c b/src/browser.c index 3c049dd..23916b4 100644 --- a/src/browser.c +++ b/src/browser.c @@ -123,9 +123,6 @@ char *do_browser(char *path) while (TRUE) { struct stat st; int i; - char *new_path; - /* The path we switch to at the "Go to Directory" - * prompt. */ /* Make sure that the cursor is off. */ curs_set(0); @@ -258,37 +255,31 @@ char *do_browser(char *path) sunder(answer); align(&answer); - new_path = real_dir_from_tilde(answer); + newpath = real_dir_from_tilde(answer); - if (new_path[0] != '/') { - new_path = charealloc(new_path, strlen(path) + + if (newpath[0] != '/') { + newpath = charealloc(newpath, strlen(path) + strlen(answer) + 1); - sprintf(new_path, "%s%s", path, answer); + sprintf(newpath, "%s%s", path, answer); } #ifndef DISABLE_OPERATINGDIR - if (check_operating_dir(new_path, FALSE)) { + if (check_operating_dir(newpath, FALSE)) { /* TRANSLATORS: This refers to the option --operatingdir, * not to --restricted. */ statusline(ALERT, _("Can't go outside of %s " "in confined mode"), full_operating_dir); - free(new_path); + free(newpath); continue; } #endif + /* In case it cannot be entered, select the specified directory + * if it is in the current list. */ + for (i = 0; i < filelist_len; i++) + if (strcmp(filelist[i], newpath) == 0) + selected = i; - dir = opendir(new_path); - if (dir == NULL) { - /* We can't open this directory for some reason. */ - statusline(ALERT, _("Error reading %s: %s"), answer, - strerror(errno)); - free(new_path); - continue; - } - - /* Start over again with the new path value. */ - free(path); - path = new_path; + /* Try opening and reading the specified directory. */ goto read_directory_contents; } else if (func == do_up_void) { if (selected >= width) -- 2.8.4