Skip to content

Commit dd36b73

Browse files
committed
repository: insert copies of MetaFile into metadata
Otherwise the metafile cache and the metadata object end up pointing to same instances which starts breaking later. Signed-off-by: Jussi Kukkonen <jkukkonen@google.com>
1 parent df6b044 commit dd36b73

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

tuf/repository/_repository.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
"""Repository Abstraction for metadata management"""
55

6+
from copy import deepcopy
67
import logging
78
from abc import ABC, abstractmethod
89
from contextlib import contextmanager, suppress
@@ -114,15 +115,15 @@ def snapshot(self, force: bool = False) -> Tuple[bool, Dict[str, MetaFile]]:
114115
for keyname, new_meta in self.targets_infos.items():
115116
if keyname not in snapshot.meta:
116117
update_version = True
117-
snapshot.meta[keyname] = new_meta
118+
snapshot.meta[keyname] = deepcopy(new_meta)
118119
continue
119120

120121
old_meta = snapshot.meta[keyname]
121122
if new_meta.version < old_meta.version:
122123
raise ValueError(f"{keyname} version rollback")
123124
if new_meta.version > old_meta.version:
124125
update_version = True
125-
snapshot.meta[keyname] = new_meta
126+
snapshot.meta[keyname] = deepcopy(new_meta)
126127
removed[keyname] = old_meta
127128

128129
if not update_version:
@@ -156,7 +157,7 @@ def timestamp(self, force: bool = False) -> Tuple[bool, Optional[MetaFile]]:
156157
if self.snapshot_info.version > timestamp.snapshot_meta.version:
157158
update_version = True
158159
removed = timestamp.snapshot_meta
159-
timestamp.snapshot_meta = self.snapshot_info
160+
timestamp.snapshot_meta = deepcopy(self.snapshot_info)
160161

161162
if not update_version:
162163
raise AbortEdit("Skip timestamp: No snapshot version changes")

0 commit comments

Comments
 (0)