CONSOLE: fix options of 'rm -r' to remove recursive option for files…

CONSOLE: fix options of 'rm -r' to remove recursive option for files automatically. Introduce new '--no-recycle-bin'. Fix deletion of files containing '&' e.g. use GetToken without escape option.
parent 7f7429f2
Pipeline #470781 canceled with stages
in 11 minutes 14 seconds
......@@ -67,11 +67,11 @@ RmHelper::ParseCommand(const char* arg)
eos::common::StringTokenizer tokenizer(arg);
tokenizer.GetLine();
while ((option = tokenizer.GetToken()).length() > 0 &&
while ((option = tokenizer.GetToken(false)).length() > 0 &&
(option.beginswith("-"))) {
if (option == "-r") {
if ((option == "-r") || (option == "-rf") || (option == "-fr")) {
rm->set_recursive(true);
} else if (option == "-f") {
} else if ((option == "-F") || (option == "--no-recycle-bin")) {
rm->set_bypassrecycle(true);
} else if (option == "-rF" || option == "-Fr") {
rm->set_recursive(true);
......@@ -105,6 +105,7 @@ RmHelper::ParseCommand(const char* arg)
if (Path2FileDenominator(path, id)) {
rm->set_fileid(id);
rm->set_recursive(false); // disable recursive option for files
path = "";
} else {
if (Path2ContainerDenominator(path, id)) {
......@@ -167,11 +168,21 @@ int com_protorm(char* arg)
void com_rm_help()
{
std::ostringstream oss;
oss << "Usage: rm [-rF] [<path>|fid:<fid-dec>|fxid:<fid-hex>|cid:<cid-dec>|cxid:<cid-hex>]"
oss << "Usage: rm [-r|-rf|-rF] [--no-recycle-bin|-F] [<path>|fid:<fid-dec>|fxid:<fid-hex>|cid:<cid-dec>|cxid:<cid-hex>]"
<< std::endl
<< " -r : remove files/directories recursively"
<< " -r | -rf : remove files/directories recursively" << std::endl
<< " - the 'f' option is a convenience option with no additional functionality!"
<< std::endl
<< " -F : remove bypassing recycling policies (you have to take the root role to use this flag!)"
<< " - the recursive flag is automatically removed it the target is a file!"
<< std::endl << std::endl
<< " --no-recycle-bin|-F : remove bypassing recycling policies" << std::endl
<< " - you have to take the root role to use this flag!"
<< std::endl << std::endl
<< " -rF | Fr : remove files/directories recursively bypassing recycling policies"
<< std::endl
<< " - you have to take the root role to use this flag!" <<
std::endl
<< " - the recursive flag is automatically removed it the target is a file!"
<< std::endl;
std::cerr << oss.str() << std::endl;
}
......@@ -49,13 +49,16 @@ com_rm(char* arg1)
goto com_rm_usage;
}
if (s1 == "-r") {
if ((s1 == "-r") || (s1 == "-rf") || (s1 == "-fr")) {
// normal recursive delete
option = "r";
path = s2;
} else if ((s1 == "-rF") || (s1 == "-Fr")) {
// recursive delete disabling the recycle bin
option = "rf";
path = s2;
} else if (s1 == "-f") {
} else if ((s1 == "-F") || (s1 == "--no-recycle-bin")) {
// delete disabling the recycle bin
option = "f";
path = s2;
} else if (s1.beginswith("-")) {
......@@ -84,17 +87,24 @@ com_rm(char* arg1)
goto com_rm_usage;
} else {
unsigned long long id;
if (Path2FileDenominator(path, id)) {
in += "&mgm.file.id=";
in += std::to_string(id).c_str();
if (option.find("r") != STR_NPOS) {
fprintf(stderr,
"error: you cannot use a recursive deletion giving a file id!\n");
goto com_rm_usage;
}
} else {
if (Path2ContainerDenominator(path, id)) {
in += "&mgm.container.id=";
in += std::to_string(id).c_str();
in += "&mgm.container.id=";
in += std::to_string(id).c_str();
} else {
path = abspath(path.c_str());
in += "&mgm.path=";
in += path;
path = abspath(path.c_str());
in += "&mgm.path=";
in += path;
}
}
......@@ -136,10 +146,13 @@ com_rm(char* arg1)
com_rm_usage:
fprintf(stdout,
"usage: rm [-rF] [<path>|fid:<fid-dec>|fxid:<fid-hex>] : remove file <path>\n");
"usage: rm [-rf] [-F|--no-recycle-bin] [<path>|fid:<fid-dec>|fxid:<fid-hex>] : remove file <path>\n");
fprintf(stdout,
" -r : remove recursivly\n");
fprintf(stdout,
" -f : default force flag is ignored because there is no file by file feedback to confirm removing\n");
fprintf(stdout,
" --no-recycle-bin :\n"
" -F : remove bypassing recycling policies (you have to take the root role to use this flag!)\n");
global_retc = EINVAL;
return (0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment