From de4b81799850aba4a8ba7e4486a2942559c8c966 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Thu, 23 Jan 2020 01:49:04 +0530 Subject: [PATCH] Lazy unmount, umount (macOS) support --- README.md | 2 +- src/nnn.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index c2adf586..7d856969 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw - Cross-dir file/all/range selection - Batch renamer (feature-limited) for selection or dir - Copy (as), move (as), delete, archive, link selection - - Notification on cp, mv, rm completion + - Dir updates, notification on cp, mv, rm completion - Copy file paths to system clipboard on select - Create (with parents), rename, duplicate (anywhere) files and dirs - Launch GUI apps, run commands, spawn a shell, toggle executable diff --git a/src/nnn.c b/src/nnn.c index ecf17e17..5bbc0004 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -473,8 +473,9 @@ static char * const utils[] = { #define MSG_BOOKMARK_KEYS 35 #define MSG_INVALID_REG 36 #define MSG_ORDER 37 +#define MSG_LAZY 38 #ifndef DIR_LIMITED_SELECTION -#define MSG_DIR_CHANGED 38 /* Must be the last entry */ +#define MSG_DIR_CHANGED 39 /* Must be the last entry */ #endif static const char * const messages[] = { @@ -516,6 +517,7 @@ static const char * const messages[] = { "bookmark keys:", "invalid regex", "toggle 'a'u / 'd'u / 'e'xtn / 'r'everse / 's'ize / 't'ime / 'v'ersion?", + "unmount failed! try lazy?", #ifndef DIR_LIMITED_SELECTION "dir changed, range sel off", /* Must be the last entry */ #endif @@ -3518,18 +3520,24 @@ static bool remote_mount(char *newpath, int *presel) */ static bool unmount(char *name, char *newpath, int *presel, char *currentpath) { +#ifdef __APPLE__ + static char cmd[] = "umount"; +#else static char cmd[] = "fusermount3"; /* Arch Linux utility */ static bool found = FALSE; +#endif char *tmp = name; struct stat sb, psb; bool child = FALSE; bool parent = FALSE; +#ifndef __APPLE__ /* On Ubuntu it's fusermount */ if (!found && !getutil(cmd)) { cmd[10] = '\0'; found = TRUE; } +#endif if (tmp && strcmp(cfgdir, currentpath) == 0) { mkpath(cfgdir, tmp, newpath); @@ -3554,9 +3562,24 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath) return FALSE; } +#ifdef __APPLE__ + if (spawn(cmd, newpath, NULL, NULL, F_NORMAL)) { +#else if (spawn(cmd, "-u", newpath, NULL, F_NORMAL)) { - printwait(messages[MSG_FAILED], presel); - return FALSE; +#endif + int r = get_input(messages[MSG_LAZY]); + + if (r != 'y' && r != 'Y') + return FALSE; + +#ifdef __APPLE__ + if (spawn(cmd, "-l", newpath, NULL, F_NORMAL)) { +#else + if (spawn(cmd, "-uz", newpath, NULL, F_NORMAL)) { +#endif + printwait(messages[MSG_FAILED], presel); + return FALSE; + } } return TRUE; @@ -5877,16 +5900,8 @@ int main(int argc, char *argv[]) char *session = NULL; int opt; - while ((opt = getopt(argc, argv, "HSKaAb:cdeEgnop:QrRs:t:vVxh")) != -1) { + while ((opt = getopt(argc, argv, "aAb:cdeEgHKnop:QrRs:St:vVxh")) != -1) { switch (opt) { - case 'S': - cfg.blkorder = 1; - nftw_fn = sum_bsize; - blk_shift = ffs(S_BLKSIZE) - 1; // fallthrough - case 'd': - cfg.showdetail = 1; - printptr = &printent_long; - break; case 'a': cfg.mtime = 0; break; @@ -5899,6 +5914,14 @@ int main(int argc, char *argv[]) case 'c': cfg.cliopener = 1; break; + case 'S': + cfg.blkorder = 1; + nftw_fn = sum_bsize; + blk_shift = ffs(S_BLKSIZE) - 1; // fallthrough + case 'd': + cfg.showdetail = 1; + printptr = &printent_long; + break; case 'e': cfg.useeditor = 1; break; @@ -5912,6 +5935,9 @@ int main(int argc, char *argv[]) case 'H': cfg.showhidden = 1; break; + case 'K': + check_key_collision(); + return _SUCCESS; case 'n': cfg.filtermode = 1; break; @@ -5953,9 +5979,6 @@ int main(int argc, char *argv[]) case 't': idletimeout = xatoi(optarg); break; - case 'K': - check_key_collision(); - return _SUCCESS; case 'v': namecmpfn = &xstrverscasecmp; break;