aboutsummaryrefslogtreecommitdiffstats
path: root/src/nnn.c
diff options
context:
space:
mode:
authorGravatar Mischievous Meerkat <engineerarun@gmail.com>2019-07-12 18:28:21 +0530
committerGravatar GitHub <noreply@github.com>2019-07-12 18:28:21 +0530
commit87d91251aeae520a27cae2e41c52811f513946de (patch)
tree3486b8df8217edb778e23cc0048e75f540c8d7f1 /src/nnn.c
parent33062d7c6e6b509c9ba9d33d4c26239b0a507a54 (diff)
parentd640de258963ed174321cd161871da66cf2f4931 (diff)
downloadnnn-87d91251aeae520a27cae2e41c52811f513946de.tar.gz
Merge pull request #305 from 0xACE/fosterhome
Find a parent when CWD disappears
Diffstat (limited to 'src/nnn.c')
-rw-r--r--src/nnn.c29
1 files changed, 26 insertions, 3 deletions
diff --git a/src/nnn.c b/src/nnn.c
index dbd54f2..bb2e285 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -3297,11 +3297,34 @@ nochange:
if (getppid() == 1)
_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)) {
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);