Skip to content

Commit 8d7b09d

Browse files
tavisitccaffy
authored andcommitted
CONSOLE: eos rm two or more files at once. Fixes EOS-4147
1 parent 07d6a23 commit 8d7b09d

2 files changed

Lines changed: 108 additions & 9 deletions

File tree

console/commands/com_proto_rm.cc

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ RmHelper::ParseCommand(const char* arg)
6868
eos::console::RmProto* rm = mReq.mutable_rm();
6969
eos::common::StringTokenizer tokenizer(arg);
7070
bool noconfirmation = false;
71-
71+
7272
tokenizer.GetLine();
7373

7474
while ((option = tokenizer.GetToken(false)).length() > 0 &&
@@ -130,7 +130,8 @@ RmHelper::ParseCommand(const char* arg)
130130
eos::common::Path cPath(path.c_str());
131131

132132
if (path.length()) {
133-
mNeedsConfirmation = rm->recursive() && (cPath.GetSubPathSize() < 4) && !noconfirmation;
133+
mNeedsConfirmation =
134+
rm->recursive() && (cPath.GetSubPathSize() < 4) && !noconfirmation;
134135
}
135136

136137
return true;
@@ -146,22 +147,81 @@ int com_protorm(char* arg)
146147
global_retc = EINVAL;
147148
return EINVAL;
148149
}
150+
eos::common::StringTokenizer tokenizer(arg);
151+
tokenizer.GetLine();
149152

150-
RmHelper rm(gGlobalOpts);
153+
std::vector<std::string> paths;
154+
std::string optStr;
155+
std::string currentPath;
156+
bool inOptions = true;
157+
158+
XrdOucString token;
159+
while ((token = tokenizer.GetToken(false)).length() > 0) {
160+
if (inOptions && token.beginswith("-")) {
161+
if (!optStr.empty()) {
162+
optStr += " ";
163+
}
164+
optStr += token.c_str();
165+
} else {
166+
inOptions = false;
167+
168+
// Check if this is a new path
169+
if (token.beginswith("/") || token.beginswith("fid:") ||
170+
token.beginswith("fxid:") || token.beginswith("cid:") ||
171+
token.beginswith("cxid:")) {
172+
// Save previous path if exists
173+
if (!currentPath.empty()) {
174+
paths.push_back(std::move(currentPath));
175+
}
176+
currentPath = token.c_str();
177+
} else {
178+
// Continue current path
179+
if (!currentPath.empty()) {
180+
currentPath += " ";
181+
}
182+
currentPath += token.c_str();
183+
}
184+
}
185+
}
186+
187+
if (!currentPath.empty()) {
188+
paths.push_back(std::move(currentPath));
189+
}
151190

152-
if (!rm.ParseCommand(arg)) {
191+
if (paths.empty()) {
153192
com_rm_help();
154193
global_retc = EINVAL;
155194
return EINVAL;
156195
}
157196

158-
if (rm.NeedsConfirmation() && !rm.ConfirmOperation()) {
159-
global_retc = EINTR;
160-
return EINTR;
161-
}
197+
// Execute rm for each path
198+
int retc = 0;
199+
for (const auto& path : paths) {
200+
std::string cmdArg = optStr;
201+
if (!cmdArg.empty()) {
202+
cmdArg += " ";
203+
}
204+
cmdArg += path;
205+
206+
RmHelper rm(gGlobalOpts);
207+
208+
if (!rm.ParseCommand(cmdArg.c_str())) {
209+
com_rm_help();
210+
global_retc = EINVAL;
211+
return EINVAL;
212+
}
162213

163-
global_retc = rm.Execute(true, true);
214+
if (rm.NeedsConfirmation() && !rm.ConfirmOperation()) {
215+
retc = EINTR;
216+
continue;
217+
}
218+
219+
if (const int rc = rm.Execute(true, true); rc != 0) {
220+
retc = rc;
221+
}
222+
}
164223

224+
global_retc = retc;
165225
return global_retc;
166226
}
167227

test/eos-instance-test

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,45 @@ runtest "### Stat file " unix SUCCESS "" command eos stat "$rmTestDir/regexx*p
18991899
runtest "### Rm file " unix SUCCESS "" command eos rm --no-globbing "$rmTestDir/regexx*p.tt\.ern"
19001900
runtest "### Stat file " unix ERROR "" command eos stat "$rmTestDir/regexx*p.tt\.ern"
19011901

1902+
# ------------------------------------------------------------------------------
1903+
# Test multiple file removal
1904+
# ------------------------------------------------------------------------------
1905+
RM_MULTI1="/eos/$EOS_TEST_INSTANCE/test/instancetest/multi 1.txt"
1906+
RM_MULTI2="/eos/$EOS_TEST_INSTANCE/test/instancetest/multi 2.txt"
1907+
RM_MULTI3="/eos/$EOS_TEST_INSTANCE/test/instancetest/ multi3 .txt"
1908+
1909+
runtest "### CP " unix SUCCESS "" eos cp /etc/passwd "'${RM_MULTI1}'"
1910+
runtest "### CP " unix SUCCESS "" eos cp /etc/passwd "'${RM_MULTI2}'"
1911+
runtest "### CP " unix SUCCESS "" eos cp /etc/passwd "'${RM_MULTI3}'"
1912+
runtest "### Delay " unix SUCCESS "" delay 7
1913+
runtest "### Rm multi " unix SUCCESS "" eos rm "'${RM_MULTI1}'" "'${RM_MULTI2}'" "'${RM_MULTI3}'"
1914+
runtest "### Delay " unix SUCCESS "" delay 7
1915+
runtest "### Stat " unix ERROR "" eos stat "'${RM_MULTI1}'"
1916+
runtest "### Stat " unix ERROR "" eos stat "'${RM_MULTI2}'"
1917+
runtest "### Stat " unix ERROR "" eos stat "'${RM_MULTI3}'"
1918+
1919+
# ------------------------------------------------------------------------------
1920+
# Test multiple recursive directory removal
1921+
# ------------------------------------------------------------------------------
1922+
RM_DIR1="/eos/$EOS_TEST_INSTANCE/test/instancetest/rmdir1"
1923+
RM_DIR2="/eos/$EOS_TEST_INSTANCE/test/instancetest/rmdir2"
1924+
RM_DIR3="/eos/$EOS_TEST_INSTANCE/test/instancetest/rmdir3"
1925+
1926+
runtest "### Mkdir " unix SUCCESS "" eos mkdir -p ${RM_DIR1}
1927+
runtest "### Mkdir " unix SUCCESS "" eos mkdir -p ${RM_DIR2}
1928+
runtest "### Mkdir " unix SUCCESS "" eos mkdir -p ${RM_DIR3}
1929+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR1}/file1.txt
1930+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR1}/file2.txt
1931+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR2}/file1.txt
1932+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR2}/file2.txt
1933+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR3}/file1.txt
1934+
runtest "### Touch " unix SUCCESS "" eos touch ${RM_DIR3}/file2.txt
1935+
runtest "### Rm -r multi " unix SUCCESS "" eos rm -r ${RM_DIR1} ${RM_DIR2} ${RM_DIR3}
1936+
runtest "### Delay " unix SUCCESS "" delay 7
1937+
runtest "### Stat " unix ERROR "" eos stat ${RM_DIR1}
1938+
runtest "### Stat " unix ERROR "" eos stat ${RM_DIR2}
1939+
runtest "### Stat " unix ERROR "" eos stat ${RM_DIR3}
1940+
19021941
# Cleanup everything
19031942
runtest "### Cleanup " unix SUCCESS "" eos rm -rF $rmTestDir/
19041943

0 commit comments

Comments
 (0)