Skip to content

Commit 674d1cb

Browse files
author
Ahmed Bilal
committed
[IO] Fix rootcp --replace flag not working with recursive copy
The --replace flag was not being checked when copying regular objects (non-tree, non-collection) in recursive mode. This caused objects to be written with new cycles instead of replacing existing ones. Added replaceOption check in the else block of copyRootObjectRecursive() to delete existing objects before writing replacements. Fixes #7052
1 parent 7b3872e commit 674d1cb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

main/python/cmdLineUtils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,13 +709,25 @@ def copyRootObjectRecursive(sourceFile, sourcePathSplit, destFile, destPathSplit
709709
changeDirectory(destFile, destPathSplit)
710710
obj.Write(setName, ROOT.TObject.kSingleKey)
711711
else:
712+
if replaceOption and isExisting(destFile, destPathSplit + [objectName]):
713+
retcodeTemp = deleteObject(destFile, destPathSplit + [objectName])
714+
if retcodeTemp:
715+
retcode += retcodeTemp
716+
obj.Delete()
717+
continue
712718
if setName != "":
713719
if isinstance(obj, ROOT.TNamed):
714720
obj.SetName(setName)
715721
else:
716722
if isinstance(obj, ROOT.TNamed):
717723
obj.SetName(objectName)
718724
changeDirectory(destFile, destPathSplit)
725+
obj.Write()
726+
obj.SetName(setName)
727+
else:
728+
if isinstance(obj, ROOT.TNamed):
729+
obj.SetName(objectName)
730+
changeDirectory(destFile, destPathSplit)
719731
obj.Write()
720732
obj.Delete()
721733
changeDirectory(destFile, destPathSplit)

0 commit comments

Comments
 (0)