aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-04-12 17:12:14 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-04-12 17:12:14 +0530
commit2b3214bd582f4cd923b4ad9ec876008345aeeabc (patch)
treeb1d67d0d5bef28dc710144a4921289114a5d613c /src
parent5e0049b6facb4477290e7c1b3c65384ced7d0593 (diff)
downloadnnn-2b3214bd582f4cd923b4ad9ec876008345aeeabc.tar.gz
Simplify finding valid parent
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 87f02b3..0ac2da7 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3700,13 +3700,16 @@ static char *visit_parent(char *path, char *newpath, int *presel)
/* There is no going back */
if (istopdir(path)) {
/* Continue in navigate-as-you-type mode, if enabled */
- if (cfg.filtermode)
+ if (cfg.filtermode && presel)
*presel = FILTER;
return NULL;
}
/* Use a copy as dirname() may change the string passed */
- xstrsncpy(newpath, path, PATH_MAX);
+ if (newpath)
+ xstrsncpy(newpath, path, PATH_MAX);
+ else
+ newpath = path;
dir = dirname(newpath);
if (access(dir, R_OK) == -1) {
@@ -3717,29 +3720,15 @@ static char *visit_parent(char *path, char *newpath, int *presel)
return dir;
}
-static void find_accessible_parent(char *path, char *newpath, char *lastname, int *presel)
+static void valid_parent(char *path, char *lastname)
{
- char *dir;
-
/* Save history */
xstrsncpy(lastname, xbasename(path), NAME_MAX + 1);
- xstrsncpy(newpath, path, PATH_MAX);
- while (true) {
- dir = visit_parent(path, newpath, presel);
- if (istopdir(path) || istopdir(newpath)) {
- if (!dir)
- dir = dirname(newpath);
+ while (!istopdir(path))
+ if (visit_parent(path, NULL, NULL))
break;
- }
- if (!dir) {
- xstrsncpy(path, newpath, PATH_MAX);
- continue;
- }
- break;
- }
- xstrsncpy(path, dir, PATH_MAX);
printwarn(NULL);
xdelay(XDELAY_INTERVAL_MS);
}
@@ -5137,7 +5126,7 @@ begin:
*/
if (access(path, R_OK) == -1) {
DPRINTF_S("directory inaccessible");
- find_accessible_parent(path, newpath, lastname, &presel);
+ valid_parent(path, lastname);
setdirwatch();
}