mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Simplify finding valid parent
This commit is contained in:
parent
5e0049b6fa
commit
2b3214bd58
29
src/nnn.c
29
src/nnn.c
|
@ -3700,13 +3700,16 @@ static char *visit_parent(char *path, char *newpath, int *presel)
|
||||||
/* There is no going back */
|
/* There is no going back */
|
||||||
if (istopdir(path)) {
|
if (istopdir(path)) {
|
||||||
/* Continue in navigate-as-you-type mode, if enabled */
|
/* Continue in navigate-as-you-type mode, if enabled */
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode && presel)
|
||||||
*presel = FILTER;
|
*presel = FILTER;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Use a copy as dirname() may change the string passed */
|
/* 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);
|
dir = dirname(newpath);
|
||||||
if (access(dir, R_OK) == -1) {
|
if (access(dir, R_OK) == -1) {
|
||||||
|
@ -3717,29 +3720,15 @@ static char *visit_parent(char *path, char *newpath, int *presel)
|
||||||
return dir;
|
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 */
|
/* Save history */
|
||||||
xstrsncpy(lastname, xbasename(path), NAME_MAX + 1);
|
xstrsncpy(lastname, xbasename(path), NAME_MAX + 1);
|
||||||
|
|
||||||
xstrsncpy(newpath, path, PATH_MAX);
|
while (!istopdir(path))
|
||||||
while (true) {
|
if (visit_parent(path, NULL, NULL))
|
||||||
dir = visit_parent(path, newpath, presel);
|
|
||||||
if (istopdir(path) || istopdir(newpath)) {
|
|
||||||
if (!dir)
|
|
||||||
dir = dirname(newpath);
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (!dir) {
|
|
||||||
xstrsncpy(path, newpath, PATH_MAX);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
xstrsncpy(path, dir, PATH_MAX);
|
|
||||||
printwarn(NULL);
|
printwarn(NULL);
|
||||||
xdelay(XDELAY_INTERVAL_MS);
|
xdelay(XDELAY_INTERVAL_MS);
|
||||||
}
|
}
|
||||||
|
@ -5137,7 +5126,7 @@ begin:
|
||||||
*/
|
*/
|
||||||
if (access(path, R_OK) == -1) {
|
if (access(path, R_OK) == -1) {
|
||||||
DPRINTF_S("directory inaccessible");
|
DPRINTF_S("directory inaccessible");
|
||||||
find_accessible_parent(path, newpath, lastname, &presel);
|
valid_parent(path, lastname);
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue