mirror of
https://github.com/jarun/nnn.git
synced 2025-02-26 03:01:32 +00:00
Fix #637: remove mount dir after unmount
This commit is contained in:
parent
4d4f72460d
commit
65cf067dc4
1 changed files with 33 additions and 24 deletions
57
src/nnn.c
57
src/nnn.c
|
@ -1787,7 +1787,8 @@ static void rmmulstr(char *buf)
|
||||||
confirm_force(TRUE), selpath);
|
confirm_force(TRUE), selpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xrm(char *fpath)
|
/* Returns TRUE if file is removed, else FALSE */
|
||||||
|
static bool xrm(char *fpath)
|
||||||
{
|
{
|
||||||
if (g_state.trash)
|
if (g_state.trash)
|
||||||
spawn("trash-put", fpath, NULL, F_NORMAL);
|
spawn("trash-put", fpath, NULL, F_NORMAL);
|
||||||
|
@ -1797,6 +1798,8 @@ static void xrm(char *fpath)
|
||||||
rm_opts[1] = confirm_force(FALSE);
|
rm_opts[1] = confirm_force(FALSE);
|
||||||
spawn("rm", rm_opts, fpath, F_NORMAL | F_CHKRTN);
|
spawn("rm", rm_opts, fpath, F_NORMAL | F_CHKRTN);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return (access(fpath, F_OK) == -1); /* File is removed */
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint lines_in_file(int fd, char *buf, size_t buflen)
|
static uint lines_in_file(int fd, char *buf, size_t buflen)
|
||||||
|
@ -3920,7 +3923,7 @@ static bool archive_mount(char *newpath)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool remote_mount(char *newpath, char *currentpath)
|
static bool remote_mount(char *newpath)
|
||||||
{
|
{
|
||||||
uchar flag = F_CLI;
|
uchar flag = F_CLI;
|
||||||
int opt;
|
int opt;
|
||||||
|
@ -3947,21 +3950,12 @@ static bool remote_mount(char *newpath, char *currentpath)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
tmp = xreadline(NULL, messages[MSG_HOSTNAME]);
|
tmp = xreadline(NULL, "remote name: ");
|
||||||
if (!tmp[0]) {
|
if (!tmp[0]) {
|
||||||
printmsg(messages[MSG_CANCEL]);
|
printmsg(messages[MSG_CANCEL]);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tmp[0] == '-' && !tmp[1]) {
|
|
||||||
if (!strcmp(cfgdir, currentpath) && ndents && (dents[cur].flags & DIR_OR_LINK_TO_DIR))
|
|
||||||
xstrsncpy(tmp, dents[cur].name, NAME_MAX + 1);
|
|
||||||
else {
|
|
||||||
printmsg(messages[MSG_FAILED]);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Create the mount point */
|
/* Create the mount point */
|
||||||
mkpath(cfgdir, tmp, newpath);
|
mkpath(cfgdir, tmp, newpath);
|
||||||
if (!xmktree(newpath, TRUE)) {
|
if (!xmktree(newpath, TRUE)) {
|
||||||
|
@ -3995,6 +3989,7 @@ static bool remote_mount(char *newpath, char *currentpath)
|
||||||
/*
|
/*
|
||||||
* Unmounts if the directory represented by name is a mount point.
|
* Unmounts if the directory represented by name is a mount point.
|
||||||
* Otherwise, asks for hostname
|
* Otherwise, asks for hostname
|
||||||
|
* Returns TRUE if directory needs to be refreshed *.
|
||||||
*/
|
*/
|
||||||
static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
||||||
{
|
{
|
||||||
|
@ -4008,6 +4003,7 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
||||||
struct stat sb, psb;
|
struct stat sb, psb;
|
||||||
bool child = FALSE;
|
bool child = FALSE;
|
||||||
bool parent = FALSE;
|
bool parent = FALSE;
|
||||||
|
bool hovered = TRUE;
|
||||||
|
|
||||||
#ifndef __APPLE__
|
#ifndef __APPLE__
|
||||||
/* On Ubuntu it's fusermount */
|
/* On Ubuntu it's fusermount */
|
||||||
|
@ -4031,6 +4027,7 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
||||||
tmp = xreadline(NULL, messages[MSG_HOSTNAME]);
|
tmp = xreadline(NULL, messages[MSG_HOSTNAME]);
|
||||||
if (!tmp[0])
|
if (!tmp[0])
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
hovered = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create the mount point */
|
/* Create the mount point */
|
||||||
|
@ -4058,7 +4055,12 @@ static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
if (rmdir(newpath) == -1) {
|
||||||
|
printwarn(presel);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lock_terminal(void)
|
static void lock_terminal(void)
|
||||||
|
@ -4863,6 +4865,15 @@ static void handle_screen_move(enum action sel)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void copynextname(char *lastname)
|
||||||
|
{
|
||||||
|
if (cur) {
|
||||||
|
cur += (cur != (ndents - 1)) ? 1 : -1;
|
||||||
|
copycurname();
|
||||||
|
} else
|
||||||
|
lastname[0] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
static int handle_context_switch(enum action sel)
|
static int handle_context_switch(enum action sel)
|
||||||
{
|
{
|
||||||
int r = -1;
|
int r = -1;
|
||||||
|
@ -5728,7 +5739,7 @@ nochange:
|
||||||
break;
|
break;
|
||||||
} // fallthrough
|
} // fallthrough
|
||||||
case SEL_REMOTE:
|
case SEL_REMOTE:
|
||||||
if (sel == SEL_REMOTE && !remote_mount(newpath, path)) {
|
if (sel == SEL_REMOTE && !remote_mount(newpath)) {
|
||||||
presel = MSGWAIT;
|
presel = MSGWAIT;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
@ -6057,16 +6068,10 @@ nochange:
|
||||||
tmp = (listpath && xstrcmp(path, listpath) == 0)
|
tmp = (listpath && xstrcmp(path, listpath) == 0)
|
||||||
? prefixpath : path;
|
? prefixpath : path;
|
||||||
mkpath(tmp, dents[cur].name, newpath);
|
mkpath(tmp, dents[cur].name, newpath);
|
||||||
xrm(newpath);
|
if (!xrm(newpath))
|
||||||
|
|
||||||
if (access(newpath, F_OK) == 0) /* File not removed */
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (cur) {
|
copynextname(lastname);
|
||||||
cur += (cur != (ndents - 1)) ? 1 : -1;
|
|
||||||
copycurname();
|
|
||||||
} else
|
|
||||||
lastname[0] = '\0';
|
|
||||||
|
|
||||||
if (cfg.filtermode || filterset())
|
if (cfg.filtermode || filterset())
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
@ -6414,8 +6419,12 @@ nochange:
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_UMOUNT:
|
case SEL_UMOUNT:
|
||||||
tmp = ndents ? dents[cur].name : NULL;
|
tmp = ndents ? dents[cur].name : NULL;
|
||||||
unmount(tmp, newpath, &presel, path);
|
if (!unmount(tmp, newpath, &presel, path))
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
|
/* Dir removed, go to next entry */
|
||||||
|
copynextname(lastname);
|
||||||
|
goto begin;
|
||||||
case SEL_SESSIONS:
|
case SEL_SESSIONS:
|
||||||
r = get_input(messages[MSG_SSN_OPTS]);
|
r = get_input(messages[MSG_SSN_OPTS]);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue