From 7d9ac9f6290c0c1610353bd85c938711e6231d68 Mon Sep 17 00:00:00 2001 From: Johanna Bahl Date: Mon, 18 Nov 2024 18:05:55 +0100 Subject: [PATCH] Fix distrusted check when writing to store --- .../20241118_180122_jb_PL_133161_distrust_check.rst | 3 +++ src/backy/rbd/tests/test_source.py | 12 ++++++++++++ src/backy/repository.py | 9 ++------- 3 files changed, 17 insertions(+), 7 deletions(-) create mode 100644 changelog.d/20241118_180122_jb_PL_133161_distrust_check.rst diff --git a/changelog.d/20241118_180122_jb_PL_133161_distrust_check.rst b/changelog.d/20241118_180122_jb_PL_133161_distrust_check.rst new file mode 100644 index 0000000..255c05f --- /dev/null +++ b/changelog.d/20241118_180122_jb_PL_133161_distrust_check.rst @@ -0,0 +1,3 @@ +.. A new scriv changelog fragment. + +- Fix check for distrusted revisions when writing to store diff --git a/src/backy/rbd/tests/test_source.py b/src/backy/rbd/tests/test_source.py index 1bf749d..d243dc9 100644 --- a/src/backy/rbd/tests/test_source.py +++ b/src/backy/rbd/tests/test_source.py @@ -164,6 +164,18 @@ def test_gc(rbdsource, repository, log): assert len(list(rbdsource.store.ls())) == 0 +def test_open_distrusted(rbdsource, repository): + r1 = create_rev(repository, set()) + rbdsource.open(r1, "wb") + assert not rbdsource.store.force_writes + + r1.distrust() + r1.write_info() + r2 = create_rev(repository, set()) + rbdsource.open(r2, "wb") + assert rbdsource.store.force_writes + + def test_smoketest_internal(rbdsource, repository, tmp_path, log): # These copies of data are intended to be different versions of the same # file. diff --git a/src/backy/repository.py b/src/backy/repository.py index 2513762..8decee4 100644 --- a/src/backy/repository.py +++ b/src/backy/repository.py @@ -247,17 +247,12 @@ def clean_history(self) -> List[Revision]: @property def local_history(self): - """History without incomplete revisions.""" + """History without remote revisions.""" return self.get_history(local=True) @property def contains_distrusted(self) -> bool: - return any( - ( - r == Trust.DISTRUSTED - for r in self.get_history(clean=True, local=True) - ) - ) + return any((r.trust == Trust.DISTRUSTED for r in self.local_history)) def validate_tags(self, tags): missing_tags = (