diff --git a/main/python/cmdLineUtils.py b/main/python/cmdLineUtils.py index f3af283b197db..2c5e1adf5c9f9 100644 --- a/main/python/cmdLineUtils.py +++ b/main/python/cmdLineUtils.py @@ -692,19 +692,18 @@ def copyRootObjectRecursive(sourceFile, sourcePathSplit, destFile, destPathSplit newT.Write() else: obj = key.ReadObj() - if replaceOption and isExisting(destFile, destPathSplit + [setName]): - changeDirectory(destFile, destPathSplit) - otherObj = getFromDirectory(setName) - retcodeTemp = deleteObject(destFile, destPathSplit + [setName]) + # Determine the actual name that will be written + actualName = setName if setName != "" else objectName + + # Delete existing object if replace option is enabled + if replaceOption and isExisting(destFile, destPathSplit + [actualName]): + retcodeTemp = deleteObject(destFile, destPathSplit + [actualName]) if retcodeTemp: retcode += retcodeTemp + obj.Delete() continue - else: - if isinstance(obj, ROOT.TNamed): - obj.SetName(setName) - changeDirectory(destFile, destPathSplit) - obj.Write() - elif issubclass(obj.__class__, ROOT.TCollection): + + if issubclass(obj.__class__, ROOT.TCollection): # probably the object was written with kSingleKey changeDirectory(destFile, destPathSplit) obj.Write(setName, ROOT.TObject.kSingleKey) diff --git a/roottest/main/CMakeLists.txt b/roottest/main/CMakeLists.txt index 8b81e9a5da861..6cfead42b8a9a 100644 --- a/roottest/main/CMakeLists.txt +++ b/roottest/main/CMakeLists.txt @@ -368,11 +368,27 @@ ROOTTEST_ADD_TEST(SimpleRootcp5CheckOutput ROOTTEST_ADD_TEST(SimpleRootcp5Clean COMMAND ${PY_TOOLS_PREFIX}/rootrm${pyext} -r copy5.root FIXTURES_REQUIRED main-SimpleRootcp5CheckOutput-fixture) -######################################################################### -############################# ROOMV TESTS ############################ -ROOTTEST_ADD_TEST(SimpleRootmv1PrepareInput - COMMAND ${PY_TOOLS_PREFIX}/rootcp${pyext} --recreate -r test.root move1.root + +ROOTTEST_ADD_TEST(RootcpReplaceRecursivePrepareInput + COMMAND ${PY_TOOLS_PREFIX}/rootcp${pyext} --recreate -r test.root copy_replace_recursive.root + FIXTURES_SETUP main-RootcpReplaceRecursivePrepareInput-fixture) + +ROOTTEST_ADD_TEST(RootcpReplaceRecursive + COMMAND ${PY_TOOLS_PREFIX}/rootcp${pyext} --replace -r copy_replace_recursive.root:tof copy_replace_recursive.root:tof + FIXTURES_REQUIRED main-RootcpReplaceRecursivePrepareInput-fixture + FIXTURES_SETUP main-RootcpReplaceRecursive-fixture) + +ROOTTEST_ADD_TEST(RootcpReplaceRecursiveCheckOutput + COMMAND ${TOOLS_PREFIX}/rootls${exeext} -1 copy_replace_recursive.root:tof + OUTREF RootcpReplaceRecursive.ref + FIXTURES_REQUIRED main-RootcpReplaceRecursive-fixture + FIXTURES_SETUP main-RootcpReplaceRecursiveCheckOutput-fixture + ENVIRONMENT ${test_env}) + +ROOTTEST_ADD_TEST(RootcpReplaceRecursiveClean + COMMAND ${PY_TOOLS_PREFIX}/rootrm${pyext} -r copy_replace_recursive.root + FIXTURES_REQUIRED main-RootcpReplaceRecursiveCheckOutput-fixture) FIXTURES_SETUP main-SimpleRootmv1PrepareInput-fixture) ROOTTEST_ADD_TEST(SimpleRootmv1 diff --git a/roottest/main/RootcpReplaceRecursive.ref b/roottest/main/RootcpReplaceRecursive.ref new file mode 100644 index 0000000000000..459126e912aeb --- /dev/null +++ b/roottest/main/RootcpReplaceRecursive.ref @@ -0,0 +1,22 @@ +h0_0N +h0_1N +h0_2N +h0_3N +h0_4N +h0_5N +h0_6N +h0_7N +h0_8N +h0_9N +h1_0N +h1_1N +h1_2N +h1_3N +h1_4N +h1_5N +h1_6N +h1_7N +h1_8N +h1_9N +plane0 +plane1