Skip to content

Commit 8e23b75

Browse files
author
Ahmed Bilal
committed
[IO] Fix rootcp --replace flag not working with recursive copy
When copying non-tree objects recursively, the --replace flag was checking for 'setName' instead of the actual object name that would be written. This caused objects to be written with new cycles instead of replacing existing ones. The fix determines the actual name (setName if provided, otherwise objectName) and uses that for the replacement check. Fixes #7052
1 parent 7b3872e commit 8e23b75

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

main/python/cmdLineUtils.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -692,19 +692,18 @@ def copyRootObjectRecursive(sourceFile, sourcePathSplit, destFile, destPathSplit
692692
newT.Write()
693693
else:
694694
obj = key.ReadObj()
695-
if replaceOption and isExisting(destFile, destPathSplit + [setName]):
696-
changeDirectory(destFile, destPathSplit)
697-
otherObj = getFromDirectory(setName)
698-
retcodeTemp = deleteObject(destFile, destPathSplit + [setName])
695+
# Determine the actual name that will be written
696+
actualName = setName if setName != "" else objectName
697+
698+
# Delete existing object if replace option is enabled
699+
if replaceOption and isExisting(destFile, destPathSplit + [actualName]):
700+
retcodeTemp = deleteObject(destFile, destPathSplit + [actualName])
699701
if retcodeTemp:
700702
retcode += retcodeTemp
703+
obj.Delete()
701704
continue
702-
else:
703-
if isinstance(obj, ROOT.TNamed):
704-
obj.SetName(setName)
705-
changeDirectory(destFile, destPathSplit)
706-
obj.Write()
707-
elif issubclass(obj.__class__, ROOT.TCollection):
705+
706+
if issubclass(obj.__class__, ROOT.TCollection):
708707
# probably the object was written with kSingleKey
709708
changeDirectory(destFile, destPathSplit)
710709
obj.Write(setName, ROOT.TObject.kSingleKey)

0 commit comments

Comments
 (0)