Browse Source

Add options to force file operations

master
Arun Prakash Jana 6 years ago
parent
commit
d1b4cc2beb
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 changed files with 28 additions and 12 deletions
  1. +28
    -12
      src/nnn.c

+ 28
- 12
src/nnn.c View File

@@ -476,6 +476,15 @@ static int get_input(const char *prompt)
return r; return r;
} }


static char confirm_force()
{
int r = get_input("use force? ('y/Y' confirms, else interactive)");
if (r == 'y' || r == 'Y')
return 'f'; /* forceful */

return 'i'; /* interactive */
}

/* Increase the limit on open file descriptors, if possible */ /* Increase the limit on open file descriptors, if possible */
static rlim_t max_openfds() static rlim_t max_openfds()
{ {
@@ -3135,36 +3144,38 @@ nochange:
goto nochange; goto nochange;
} }


/* Fail if copy file path isn't created */ /* Fail if copy file path isn't accessible */
if (access(g_cppath, R_OK) == -1) { if (access(g_cppath, R_OK) == -1) {
printmsg("empty selection list"); printmsg("empty selection list");
goto nochange; goto nochange;
} }


char force = confirm_force();

if (sel == SEL_CP) { if (sel == SEL_CP) {
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s -%c src cp -iRp src .", "xargs -0 -a %s -%c src cp -%cRp src .",
#else #else
"cat %s | xargs -0 -o -%c src cp -iRp src .", "cat %s | xargs -0 -o -%c src cp -%cRp src .",
#endif #endif
g_cppath, REPLACE_STR); g_cppath, REPLACE_STR, force);
} else if (sel == SEL_MV) { } else if (sel == SEL_MV) {
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s -%c src mv -i src .", "xargs -0 -a %s -%c src mv -%c src .",
#else #else
"cat %s | xargs -0 -o -%c src mv -i src .", "cat %s | xargs -0 -o -%c src mv -%c src .",
#endif #endif
g_cppath, REPLACE_STR); g_cppath, REPLACE_STR, force);
} else { /* SEL_RMMUL */ } else { /* SEL_RMMUL */
snprintf(g_buf, MAX_CMD_LEN, snprintf(g_buf, MAX_CMD_LEN,
#ifdef __linux__ #ifdef __linux__
"xargs -0 -a %s rm -ir", "xargs -0 -a %s rm -%cr",
#else #else
"cat %s | xargs -0 -o rm -ir", "cat %s | xargs -0 -o rm -%cr",
#endif #endif
g_cppath); g_cppath, force);
} }


spawn("sh", "-c", g_buf, path, F_NORMAL | F_SIGINT); spawn("sh", "-c", g_buf, path, F_NORMAL | F_SIGINT);
@@ -3175,16 +3186,21 @@ nochange:
goto begin; goto begin;
} }
case SEL_RM: case SEL_RM:
{
if (!ndents) if (!ndents)
break; break;


char rm_opts[] = "-ir";
rm_opts[1] = confirm_force();

mkpath(path, dents[cur].name, newpath, PATH_MAX); mkpath(path, dents[cur].name, newpath, PATH_MAX);
spawn("rm", "-ir", newpath, NULL, F_NORMAL | F_SIGINT); spawn("rm", rm_opts, newpath, NULL, F_NORMAL | F_SIGINT);


lastname[0] = '\0'; copycurname();
if (cfg.filtermode) if (cfg.filtermode)
presel = FILTER; presel = FILTER;
goto begin; goto begin;
}
case SEL_OPEN: // fallthrough case SEL_OPEN: // fallthrough
case SEL_ARCHIVE: case SEL_ARCHIVE:
if (!ndents) if (!ndents)


||||||
x
 
000:0
Loading…
Cancel
Save