Skip to content

Commit d025767

Browse files
committed
[main] rootcp: forbid overwriting object with itself
1 parent 666a298 commit d025767

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

main/src/rootcp.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,12 @@ static void CopyNode(const RootSource &src, const RootCpDestination &dest, NodeI
197197
// User gave a destination which is an existing directory
198198
destDirPath = dest.fPath;
199199
destFullPath = std::string(destDirPath) + "/" + node.fName;
200+
destBaseName = node.fName;
201+
}
202+
203+
if (src.fFileName == dest.fFname && srcFullPath == destFullPath) {
204+
Err() << src.fFileName << ":" << srcFullPath << ": source and destination cannot be the same\n";
205+
return;
200206
}
201207

202208
Info(2) << "cp " << src.fFileName << ":" << srcFullPath << " -> " << dest.fFname << ":" << destFullPath << "\n";

roottest/main/CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,32 @@ ROOTTEST_ADD_TEST(SimpleRootcp5CheckOutput
373373
ROOTTEST_ADD_TEST(SimpleRootcp5Clean
374374
COMMAND ${PY_TOOLS_PREFIX}/rootrm${pyext} -r copy5.root
375375
FIXTURES_REQUIRED main-SimpleRootcp5CheckOutput-fixture)
376+
377+
ROOTTEST_ADD_TEST(RootcpReplaceRecursivePrepareInput
378+
COMMAND ${TOOLS_PREFIX}/rootcp${exeext} --recreate -r test.root copy_replace_recursive.root
379+
FIXTURES_SETUP main-RootcpReplaceRecursivePrepareInput-fixture)
380+
381+
ROOTTEST_ADD_TEST(RootcpReplaceRecursiveWrong
382+
COMMAND ${TOOLS_PREFIX}/rootcp${exeext} --replace -r copy_replace_recursive.root:tof copy_replace_recursive.root
383+
FIXTURES_REQUIRED main-RootcpReplaceRecursivePrepareInput-fixture
384+
FIXTURES_SETUP main-RootcpReplaceRecursiveWrong-fixture
385+
PASSREGEX "Error in <rootcp>: copy_replace_recursive.root:tof: source and destination cannot be the same")
386+
387+
ROOTTEST_ADD_TEST(RootcpReplaceRecursive
388+
COMMAND ${TOOLS_PREFIX}/rootcp${exeext} --replace -r test.root:tof copy_replace_recursive.root
389+
FIXTURES_REQUIRED main-RootcpReplaceRecursiveWrong-fixture
390+
FIXTURES_SETUP main-RootcpReplaceRecursive-fixture)
391+
392+
ROOTTEST_ADD_TEST(RootcpReplaceRecursiveCheckOutput
393+
COMMAND ${TOOLS_PREFIX}/rootls${exeext} -1 copy_replace_recursive.root:tof
394+
OUTREF RootcpReplaceRecursive.ref
395+
FIXTURES_REQUIRED main-RootcpReplaceRecursive-fixture
396+
FIXTURES_SETUP main-RootcpReplaceRecursiveCheckOutput-fixture
397+
ENVIRONMENT ${test_env})
398+
399+
ROOTTEST_ADD_TEST(RootcpReplaceRecursiveClean
400+
COMMAND ${PY_TOOLS_PREFIX}/rootrm${pyext} -r copy_replace_recursive.root
401+
FIXTURES_REQUIRED main-RootcpReplaceRecursiveCheckOutput-fixture)
376402
#########################################################################
377403

378404
############################# ROOMV TESTS ############################
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
h0_0N
2+
h0_1N
3+
h0_2N
4+
h0_3N
5+
h0_4N
6+
h0_5N
7+
h0_6N
8+
h0_7N
9+
h0_8N
10+
h0_9N
11+
h1_0N
12+
h1_1N
13+
h1_2N
14+
h1_3N
15+
h1_4N
16+
h1_5N
17+
h1_6N
18+
h1_7N
19+
h1_8N
20+
h1_9N
21+
plane0
22+
plane1

0 commit comments

Comments
 (0)