diff options
author | 0xACE <0xACE@users.noreply.github.com> | 2019-10-13 17:23:32 +0200 |
---|---|---|
committer | Mischievous Meerkat <engineerarun@gmail.com> | 2019-10-13 20:53:32 +0530 |
commit | ab0fe6c408656718a3a27380648552828c2d0143 (patch) | |
tree | 0a0b171cafef6a1fcc13a02aa14a89d1ad58e5e7 | |
parent | 06ff2c55da3d2ce110c91f0ca344ac7e58b25914 (diff) | |
download | nnn-ab0fe6c408656718a3a27380648552828c2d0143.tar.gz |
unmount() ask for target if not found (#358)
* unmount() ask for target if not found
unmount() now properly asks for which target to unmount if it cannot
automatically deduce which folder to unmount.
* no more automatic unmounts outside of cfgdir
-rw-r--r-- | src/nnn.c | 14 |
1 files changed, 9 insertions, 5 deletions
@@ -2898,12 +2898,14 @@ static bool sshfs_mount(char *newpath, int *presel) * Unmounts if the directory represented by name is a mount point. * Otherwise, asks for hostname */ -static bool unmount(char *name, char *newpath, int *presel) +static bool unmount(char *name, char *newpath, int *presel, char *currentpath) { static char cmd[] = "fusermount3"; /* Arch Linux utility */ static bool found = FALSE; char *tmp = name; struct stat sb, psb; + bool child = false; + bool parent = false; /* On Ubuntu it's fusermount */ if (!found && !getutil(cmd)) { @@ -2911,15 +2913,17 @@ static bool unmount(char *name, char *newpath, int *presel) found = TRUE; } - if (tmp) { + if (tmp && strcmp(cfgdir, currentpath) == 0) { mkpath(cfgdir, tmp, newpath); - if ((lstat(newpath, &sb) == -1) || (lstat(dirname(newpath), &psb) == -1)) { + child = lstat(newpath, &sb) != -1; + parent = lstat(dirname(newpath), &psb) != -1; + if (!child && !parent) { *presel = MSGWAIT; return FALSE; } } - if (!tmp || (sb.st_dev == psb.st_dev)) { + if (!tmp || !child || !S_ISDIR(sb.st_mode) || (child && parent && sb.st_dev == psb.st_dev)) { tmp = xreadline(NULL, "host: "); if (!tmp[0]) return FALSE; @@ -4679,7 +4683,7 @@ nochange: goto begin; case SEL_UMOUNT: tmp = ndents ? dents[cur].name : NULL; - unmount(tmp, newpath, &presel); + unmount(tmp, newpath, &presel, path); goto nochange; case SEL_QUITCD: // fallthrough case SEL_QUIT: |