From e3393d04370a30ead0448c298016e960c4ae5fa2 Mon Sep 17 00:00:00 2001 From: 0xACE <0xaced@gmail.com> Date: Fri, 12 Jul 2019 00:45:55 +0200 Subject: Find a parent when CWD disappears The previous behaviour would exit nnn when the CWD disappeared. --- src/nnn.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/nnn.c') diff --git a/src/nnn.c b/src/nnn.c index dbd54f2..7a133ef 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3297,11 +3297,36 @@ nochange: if (getppid() == 1) _exit(0); - /* Check if CWD is deleted to avoid hang, bad idea */ + /* Check if CWD is deleted and find a existing parent */ if (access(path, F_OK)) { DPRINTF_S("dir deleted or moved"); - cfg.badexit = 1; - return; + + /* Save last working directory */ + xstrlcpy(lastdir, path, PATH_MAX); + + /* 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; + } else if (!dir) { + xstrlcpy(path, newpath, PATH_MAX); + continue; + } + break; + } + + xstrlcpy(path, dir, PATH_MAX); + + setdirwatch(); + mvprintw(xlines - 1, 0, "folder disappeared\n"); + xdelay(); + goto begin; } sel = nextsel(presel); -- cgit v1.2.3-70-g09d2 From 78ada7a8bc0f2622af461f54dc80abf10abf6f1c Mon Sep 17 00:00:00 2001 From: 0xACE <0xaced@gmail.com> Date: Fri, 12 Jul 2019 14:33:39 +0200 Subject: fixed misleading `else if` & text. removed lastdir --- src/nnn.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/nnn.c') diff --git a/src/nnn.c b/src/nnn.c index 7a133ef..4bcc55b 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3297,16 +3297,10 @@ nochange: if (getppid() == 1) _exit(0); - /* Check if CWD is deleted and find a existing parent */ + /* Check if CWD is deleted and find an existing parent */ if (access(path, F_OK)) { DPRINTF_S("dir deleted or moved"); - /* Save last working directory */ - xstrlcpy(lastdir, path, PATH_MAX); - - /* Save history */ - xstrlcpy(lastname, xbasename(path), NAME_MAX + 1); - xstrlcpy(newpath, path, PATH_MAX); while (true) { dir = visit_parent(path, newpath, &presel); @@ -3314,7 +3308,8 @@ nochange: if (!dir) dir = dirname(newpath); break; - } else if (!dir) { + } + if (!dir) { xstrlcpy(path, newpath, PATH_MAX); continue; } @@ -3324,7 +3319,7 @@ nochange: xstrlcpy(path, dir, PATH_MAX); setdirwatch(); - mvprintw(xlines - 1, 0, "folder disappeared\n"); + mvprintw(xlines - 1, 0, "cannot access directory\n"); xdelay(); goto begin; } -- cgit v1.2.3-70-g09d2 From d640de258963ed174321cd161871da66cf2f4931 Mon Sep 17 00:00:00 2001 From: 0xACE <0xaced@gmail.com> Date: Fri, 12 Jul 2019 14:55:03 +0200 Subject: Keep lastname directory selected incase the user just lost access, it would be better to remember the selected directory to keep it highlighted. --- src/nnn.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nnn.c') diff --git a/src/nnn.c b/src/nnn.c index 4bcc55b..bb2e285 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3301,6 +3301,9 @@ nochange: if (access(path, F_OK)) { DPRINTF_S("dir deleted or moved"); + /* Save history */ + xstrlcpy(lastname, xbasename(path), NAME_MAX + 1); + xstrlcpy(newpath, path, PATH_MAX); while (true) { dir = visit_parent(path, newpath, &presel); -- cgit v1.2.3-70-g09d2