GitLab unavailability on July 18, 22, 23 due to hypervisor security updates: http://cern.ch/go/BP7D

...
 
Commits (3)
......@@ -42,7 +42,7 @@ ICmdHelper::Execute(bool printError)
}
if (printError && !mMgmExec.GetError().empty()) {
std::cerr << GetError() << std::endl;
std::cerr << GetError();
}
return retc;
......@@ -164,5 +164,12 @@ ICmdHelper::GetResult()
std::string
ICmdHelper::GetError()
{
return mMgmExec.GetError();
// Add new line if necessary
std::string err = mMgmExec.GetError();
if (*err.rbegin() != '\n') {
err += '\n';
}
return err;
}
......@@ -326,7 +326,7 @@ int com_protorecycle(char* arg)
(global_retc == EIO)) {
global_retc = com_recycle(arg);
} else {
std::cerr << recycle.GetError() << std::endl;
std::cerr << recycle.GetError();
}
}
......
......@@ -82,49 +82,34 @@ RmHelper::ParseCommand(const char* arg)
}
auto path = option;
unsigned long long id;
do {
XrdOucString param = tokenizer.GetToken();
while (path.length()) {
auto identifier = rm->add_identifier();
if (param.length()) {
path += " ";
path += param;
} else {
break;
}
} while (true);
// remove escaped blanks
while (path.replace("\\ ", " "));
if (path.length() == 0) {
return false;
}
auto id = 0ull;
// Remove escaped blanks
while (path.replace("\\ ", " "));
if (Path2FileDenominator(path, id)) {
rm->set_fileid(id);
rm->set_recursive(false); // disable recursive option for files
path = "";
} else {
if (Path2ContainerDenominator(path, id)) {
rm->set_containerid(id);
path = "";
// Figure identifier
if (Path2FileDenominator(path, id)) {
identifier->set_fid(id);
} else if (Path2ContainerDenominator(path, id)) {
identifier->set_cid(id);
} else {
path = abspath(path.c_str());
rm->set_path(path.c_str());
setenv("EOS_ROUTE", path.c_str(), 1);
}
}
identifier->set_path(path.c_str());
eos::common::Path cPath(path.c_str());
// Tag confirmation flag
if (rm->recursive()) {
eos::common::Path cPath(path.c_str());
mNeedsConfirmation |= (cPath.GetSubPathSize() < 4);
}
}
if (path.length()) {
mNeedsConfirmation = rm->recursive() && (cPath.GetSubPathSize() < 4);
path = tokenizer.GetToken();
}
return true;
return rm->identifier_size() > 0;
}
//------------------------------------------------------------------------------
......@@ -158,7 +143,7 @@ int com_protorm(char* arg)
if (rm.GetError().find("no such user command") != std::string::npos) {
global_retc = com_rm(arg);
} else {
std::cerr << rm.GetError() << std::endl;
std::cerr << rm.GetError();
}
}
......@@ -168,21 +153,23 @@ int com_protorm(char* arg)
void com_rm_help()
{
std::ostringstream oss;
oss << "Usage: rm [-r|-rf|-rF] [--no-recycle-bin|-F] [<path>|fid:<fid-dec>|fxid:<fid-hex>|cid:<cid-dec>|cxid:<cid-hex>]"
oss << "Usage: rm [-r|-rf|-rF] [--no-recycle-bin|-F] <identifier> [identifier...]"
<< std::endl
<<" <identifier> = <path>|fid:<fid-dec>|fxid:<fid-hex>|cid:<cid-dec>|cxid:<cid-hex>"
<< std::endl
<< "Options:" << std::endl
<< " -r | -rf : remove files/directories recursively" << std::endl
<< " - the 'f' option is a convenience option with no additional functionality!"
<< std::endl
<< std::endl
<< " -r | -rf : remove files/directories recursively" << std::endl
<< " - the 'f' option is a convenience option with no additional functionality!"
<< " --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
<< " - 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"
<< " -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!"
<< " - you have to take the root role to use this flag!" << std::endl
<< "Remarks:" <<std::endl
<< " Wildcards are expanded but only matching files will be deleted."
<< std::endl;
std::cerr << oss.str() << std::endl;
}
This diff is collapsed.
......@@ -5,7 +5,7 @@
/************************************************************************
* EOS - the CERN Disk Storage System *
* Copyright (C) 2018 CERN/Switzerland *
* Copyright (C) 2019 CERN/Switzerland *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
......@@ -24,8 +24,8 @@
#pragma once
#include "mgm/proc/IProcCommand.hh"
#include "mgm/Namespace.hh"
#include "mgm/proc/IProcCommand.hh"
#include "proto/ConsoleRequest.pb.h"
EOSMGMNAMESPACE_BEGIN
......@@ -53,6 +53,49 @@ public:
//! asynchronous thread
//----------------------------------------------------------------------------
eos::console::ReplyProto ProcessRequest() noexcept override;
private:
//----------------------------------------------------------------------------
//! Attempts to remove file.
//!
//! @param path the file path
//! @param force bypass recycling policies
//!
//! @return 0 on success, errno otherwise
//----------------------------------------------------------------------------
int RemoveFile(const std::string path, bool force);
//----------------------------------------------------------------------------
//! Attempts to remove directory.
//!
//! @param path the directory path
//! @param force bypass recycling policies
//! @param outMsg output message string
//! @param errMsg error message string
//!
//! @return 0 on success, errno otherwise
//----------------------------------------------------------------------------
int RemoveDirectory(const std::string path, bool force,
std::string& outMsg,
std::string& errMsg);
//----------------------------------------------------------------------------
//! Attempts to remove files matching a given filter.
//! Note: directories will not be removed
//!
//! @param path directory path where filter matching is applied
//! @param filter the filter to match against
//! @param force bypass recycling policies
//! @param errMsg error message string
//!
//! @return 0 on success, errno otherwise
//----------------------------------------------------------------------------
int RemoveFilterMatch(const std::string path,
const std::string filter,
bool force,
std::string& errMsg);
};
EOSMGMNAMESPACE_END
......@@ -2,9 +2,15 @@ syntax="proto3";
package eos.console;
message RmProto {
bool Recursive = 1;
bool BypassRecycle = 2;
uint64 Fileid = 3;
string Path = 4;
uint64 Containerid = 5;
message IdentifierProto {
oneof Identifier {
uint64 Fid = 1;
uint64 Cid = 2;
string Path = 3;
}
}
bool Recursive = 4;
bool BypassRecycle = 5;
repeated IdentifierProto identifier = 6;
}
......@@ -710,6 +710,37 @@ runtest "### Rem " unix 2 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/insta
runtest "### Quota " unix 0 "" eos quota set -u 99 -p /eos/$EOS_TEST_INSTANCE/test -v 1T -i 1M
fi
################################################################################
# Remove (with multiple arguments)
################################################################################
# ------------------------------------------------------------------------------
categorie="rm"
# ------------------------------------------------------------------------------
runtest "### Mkdir " unix 0 "" eos mkdir "-p" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm"
runtest "### Chmod " unix 0 "" eos chmod "777" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm"
runtest "### Upload " unix 0 "" upload "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd1.rm"
runtest "### Upload " unix 0 "" upload "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd2.rm"
runtest "### Upload " unix 0 "" upload "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd3.rm"
runtest "### Upload " unix 0 "" upload "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/nopasswd.rm"
runtest "### Rm " unix 0 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd1.rm" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd2.rm"
runtest "### Rm " unix 0 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd*"
runtest "### Ls " unix 0 "" eos ls "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/ | wc -l | grep -w 1"
runtest "### Rm " unix 1 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/nofile" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/nopasswd.rm"
runtest "### Ls " unix 0 "" eos ls "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/ | wc -l | grep -w 0"
runtest "### Mkdir " unix 0 "" eos mkdir "-p" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passdir1"
runtest "### Mkdir " unix 0 "" eos mkdir "-p" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passdir2"
runtest "### Upload " unix 0 "" upload "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passwd.rm"
runtest "### Rm " unix 0 "" eos rm "-r" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/pass*"
runtest "### Ls " unix 0 "" eos ls "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/ | wc -l | grep -w 2"
runtest "### Rm " unix 0 "" eos rm "-r" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passdir1" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/passdir2"
runtest "### Upload " unix 0 "" eos cp "/etc/passwd" "\"/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file quoted spaces.rm\""
runtest "### Upload " unix 0 "" eos cp "/etc/passwd" "\"/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file quoted spaces 2.rm\""
runtest "### Rm " unix 0 "" eos rm "\"/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file quoted spaces.rm\"" "\"/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file quoted spaces 2.rm\""
runtest "### Upload " unix 0 "" eos cp "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file\ backslashed\ spaces.rm"
runtest "### Upload " unix 0 "" eos cp "/etc/passwd" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file\ backslashed\ spaces\ 2.rm"
runtest "### Rm " unix 0 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file\ backslashed\ spaces.rm" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/file\ backslashed\ spaces\ 2.rm"
runtest "### Rm " unix 1 "" eos rm "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/"
runtest "### Rm " unix 0 "" eos rm "-r" "/eos/$EOS_TEST_INSTANCE/test/instancetest/rm/"
################################################################################
# RECYCLE BIN TEST
################################################################################
# ------------------------------------------------------------------------------
......