Skip to content

Commit 71a7f11

Browse files
Ivana Atanasovaivanayov
Ivana Atanasova
authored andcommitted
Fix inconsistent behaviour of compute_metafile_hashes_length
Previously when `compute_metafile_hashes_length` was set to `False` `update_timestamp` did not set the hash and length values to `None` as expected. This change fixes that, so they are not `None` when `compute_metafile_hashes_length=True` and `None` when `compute_metafile_hashes_length=False` Signed-off-by: Ivana Atanasova <[email protected]>
1 parent dd5deee commit 71a7f11

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

tests/repository_simulator.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,12 +294,15 @@ def update_timestamp(self) -> None:
294294
"""Update timestamp and assign snapshot version to snapshot_meta
295295
version.
296296
"""
297-
self.timestamp.snapshot_meta.version = self.snapshot.version
298297

298+
hashes = None
299+
length = None
299300
if self.compute_metafile_hashes_length:
300301
hashes, length = self._compute_hashes_and_length(Snapshot.type)
301-
self.timestamp.snapshot_meta.hashes = hashes
302-
self.timestamp.snapshot_meta.length = length
302+
303+
self.timestamp.snapshot_meta = MetaFile(
304+
self.snapshot.version, length, hashes
305+
)
303306

304307
self.timestamp.version += 1
305308

tests/test_updater_top_level_update.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,20 @@ def test_new_targets_expired(self) -> None:
434434

435435
self._assert_files_exist([Root.type, Timestamp.type, Snapshot.type])
436436

437+
def test_compute_metafile_hashes_length(self) -> None:
438+
self.sim.compute_metafile_hashes_length = True
439+
self.sim.update_snapshot()
440+
self._run_refresh()
441+
self._assert_version_equals("timestamp", 2)
442+
self._assert_version_equals("snapshot", 2)
443+
444+
self.sim.compute_metafile_hashes_length = False
445+
self.sim.update_snapshot()
446+
self._run_refresh()
447+
448+
self._assert_version_equals("timestamp", 3)
449+
self._assert_version_equals("snapshot", 3)
450+
437451

438452
if __name__ == "__main__":
439453

0 commit comments

Comments
 (0)