mirror of
https://github.com/jarun/nnn.git
synced 2025-01-10 09:59:56 +00:00
Merge pull request #305 from 0xACE/fosterhome
Find a parent when CWD disappears
This commit is contained in:
commit
87d91251ae
29
src/nnn.c
29
src/nnn.c
|
@ -3297,11 +3297,34 @@ nochange:
|
||||||
if (getppid() == 1)
|
if (getppid() == 1)
|
||||||
_exit(0);
|
_exit(0);
|
||||||
|
|
||||||
/* Check if CWD is deleted to avoid hang, bad idea */
|
/* Check if CWD is deleted and find an existing parent */
|
||||||
if (access(path, F_OK)) {
|
if (access(path, F_OK)) {
|
||||||
DPRINTF_S("dir deleted or moved");
|
DPRINTF_S("dir deleted or moved");
|
||||||
cfg.badexit = 1;
|
|
||||||
return;
|
/* Save history */
|
||||||
|
xstrlcpy(lastname, xbasename(path), NAME_MAX + 1);
|
||||||
|
|
||||||
|
xstrlcpy(newpath, path, PATH_MAX);
|
||||||
|
while (true) {
|
||||||
|
dir = visit_parent(path, newpath, &presel);
|
||||||
|
if (istopdir(path) || istopdir(newpath)) {
|
||||||
|
if (!dir)
|
||||||
|
dir = dirname(newpath);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!dir) {
|
||||||
|
xstrlcpy(path, newpath, PATH_MAX);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
xstrlcpy(path, dir, PATH_MAX);
|
||||||
|
|
||||||
|
setdirwatch();
|
||||||
|
mvprintw(xlines - 1, 0, "cannot access directory\n");
|
||||||
|
xdelay();
|
||||||
|
goto begin;
|
||||||
}
|
}
|
||||||
|
|
||||||
sel = nextsel(presel);
|
sel = nextsel(presel);
|
||||||
|
|
Loading…
Reference in a new issue