aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar 0xACE <0xaced@gmail.com>2019-07-12 00:45:55 +0200
committerGravatar 0xACE <0xaced@gmail.com>2019-07-12 00:52:25 +0200
commite3393d04370a30ead0448c298016e960c4ae5fa2 (patch)
tree58922d190412af26f1816a47d84e08f36b4f26b2 /src
parentca714eac9067a44e5e0a7136dc6077969dd961ca (diff)
downloadnnn-e3393d04370a30ead0448c298016e960c4ae5fa2.tar.gz
Find a parent when CWD disappears
The previous behaviour would exit nnn when the CWD disappeared.
Diffstat (limited to 'src')
-rw-r--r--src/nnn.c31
1 files changed, 28 insertions, 3 deletions
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);