Modularize cp, mv, rm

This commit is contained in:
Arun Prakash Jana 2019-03-02 15:09:00 +05:30
parent fa46963dd7
commit bf7a5f25aa
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -1142,6 +1142,44 @@ static bool createdir(const char *path, mode_t mode)
return FALSE; return FALSE;
} }
static void cpstr(char *buf)
{
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
"xargs -0 -a %s -%c src %s src .", g_cppath, REPLACE_STR, cp);
#else
"cat %s | xargs -0 -o -%c src cp -iRp src .", g_cppath, REPLACE_STR);
#endif
}
static void mvstr(char *buf)
{
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
"xargs -0 -a %s -%c src %s src .", g_cppath, REPLACE_STR, mv);
#else
"cat %s | xargs -0 -o -%c src mv -i src .", g_cppath, REPLACE_STR);
#endif
}
static void rmmulstr(char *buf)
{
snprintf(buf, CMD_LEN_MAX,
#ifdef __linux__
"xargs -0 -a %s rm -%cr",
#else
"cat %s | xargs -0 -o rm -%cr",
#endif
g_cppath, confirm_force());
}
static void xrm(char *path)
{
char rm_opts[] = {'-', confirm_force(), 'r'};
spawn("rm", rm_opts, path, NULL, F_NORMAL | F_SIGINT);
}
static int digit_compare(const char *a, const char *b) static int digit_compare(const char *a, const char *b)
{ {
while (*a && *b && *a == *b) while (*a && *b && *a == *b)
@ -3457,33 +3495,13 @@ nochange:
switch (sel) { switch (sel) {
case SEL_CP: case SEL_CP:
snprintf(g_buf, CMD_LEN_MAX, cpstr(g_buf);
#ifdef __linux__
"xargs -0 -a %s -%c src %s src .",
g_cppath, REPLACE_STR, cp);
#else
"cat %s | xargs -0 -o -%c src cp -iRp src .",
g_cppath, REPLACE_STR);
#endif
break; break;
case SEL_MV: case SEL_MV:
snprintf(g_buf, CMD_LEN_MAX, mvstr(g_buf);
#ifdef __linux__
"xargs -0 -a %s -%c src %s src .",
g_cppath, REPLACE_STR, mv);
#else
"cat %s | xargs -0 -o -%c src mv -i src .",
g_cppath, REPLACE_STR);
#endif
break; break;
default: /* SEL_RMMUL */ default: /* SEL_RMMUL */
snprintf(g_buf, CMD_LEN_MAX, rmmulstr(g_buf);
#ifdef __linux__
"xargs -0 -a %s rm -%cr",
#else
"cat %s | xargs -0 -o rm -%cr",
#endif
g_cppath, confirm_force());
break; break;
} }
@ -3500,12 +3518,8 @@ nochange:
if (!ndents) if (!ndents)
break; break;
char rm_opts[] = "-ir";
rm_opts[1] = confirm_force();
mkpath(path, dents[cur].name, newpath); mkpath(path, dents[cur].name, newpath);
spawn("rm", rm_opts, newpath, NULL, F_NORMAL | F_SIGINT); xrm(newpath);
/* Don't optimize cur if filtering is on */ /* Don't optimize cur if filtering is on */
if (!cfg.filtermode && cur && access(newpath, F_OK) == -1) if (!cfg.filtermode && cur && access(newpath, F_OK) == -1)