From f246e79d8b75702aa06fb69c72b21eb526cccf2c Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Tue, 28 Jun 2016 11:11:19 +0200 Subject: [PATCH 1/2] browser: elide an opendir() --- src/browser.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/browser.c b/src/browser.c index 9bcecfa..5fc0e6e 100644 --- a/src/browser.c +++ b/src/browser.c @@ -72,9 +72,6 @@ char *do_browser(char *path) read_directory_contents: /* We come here when we refresh or select a new directory. */ - /* Start with no key pressed. */ - kbinput = ERR; - path = mallocstrassn(path, get_full_path(newpath ? newpath : path)); if (path != NULL && newpath != NULL) @@ -94,6 +91,9 @@ char *do_browser(char *path) present_name = mallocstrcpy(present_name, filelist[selected]); } + /* Start with no key pressed. */ + kbinput = ERR; + assert(path != NULL && path[strlen(path) - 1] == '/'); if (dir != NULL) { @@ -132,17 +132,13 @@ char *do_browser(char *path) bottombars(MBROWSER); #ifndef NANO_TINY + /* If the window resized, also refresh the file list. */ if (kbinput == KEY_WINCH) { /* Remember the selected file, to be able to reselect it. */ present_name = strdup(filelist[selected]); - - /* Reopen the current directory. */ - dir = opendir(path); - if (dir != NULL) - goto read_directory_contents; - - statusline(ALERT, _("Error reading %s: %s"), path, strerror(errno)); - kbinput = ERR; + /* Reread the contents of the current directory. */ + newpath = strdup(present_path); + goto read_directory_contents; } #endif /* Display (or redisplay) the file list if we don't have a key yet, @@ -194,15 +190,15 @@ char *do_browser(char *path) if (func == total_refresh) { total_redraw(); - /* Simulate a window resize to force a directory reread. */ #ifndef NANO_TINY + /* Simulate a window resize to force a directory reread. */ kbinput = KEY_WINCH; #endif } else if (func == do_help_void) { #ifndef DISABLE_HELP do_help_void(); - /* The window dimensions might have changed, so act as if. */ #ifndef NANO_TINY + /* The window dimensions might have changed, so act as if. */ kbinput = KEY_WINCH; #endif #else -- 2.8.4