Skip to content

Commit

Permalink
Merge pull request #193 from jku/preserve-custom-metadata-in-target-f…
Browse files Browse the repository at this point in the history
…iles

repo: Preserve custom fields in TargetFiles
  • Loading branch information
jku authored Feb 26, 2024
2 parents 4974744 + 7ed3a3a commit ef2d953
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions repo/tuf_on_ci/_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,20 @@ def update_targets(self, rolename: str) -> bool:
if rolename in ["root", "timestamp", "snapshot"]:
return False

new_target_dict = self._build_targets(
new_tfiles = self._build_targets(
os.path.join(self._dir, "..", "targets"), rolename
)
with self.edit_targets(rolename) as targets:
# Keep any existing custom fields
for path, tfile in targets.targets.items():
if path in new_tfiles:
new_tfiles[path].unrecognized_fields = tfile.unrecognized_fields

# if targets dict has no changes, cancel the metadata edit
if targets.targets == new_target_dict:
if targets.targets == new_tfiles:
raise AbortEdit("No target changes needed")

targets.targets = new_target_dict
targets.targets = new_tfiles
return True

return False
Expand Down

0 comments on commit ef2d953

Please sign in to comment.