From 1b9805842cb0548bf8fc6c006d9018bb1a0cda8c Mon Sep 17 00:00:00 2001 From: sagar Date: Sat, 21 Mar 2026 23:18:12 +0530 Subject: [PATCH] move ProgressIndicatorCounter import to module level and fix progress guard pattern --- src/borg/repository.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/borg/repository.py b/src/borg/repository.py index 337d8fb20..9af792b80 100644 --- a/src/borg/repository.py +++ b/src/borg/repository.py @@ -12,7 +12,7 @@ from borgstore.backends.errors import BackendAlreadyExists as StoreBackendAlread from .constants import * # NOQA from .hashindex import ChunkIndex, ChunkIndexEntry -from .helpers import Error, ErrorWithTraceback, IntegrityError +from .helpers import Error, ErrorWithTraceback, IntegrityError, ProgressIndicatorCounter from .helpers import Location from .helpers import bin_to_hex, hex_to_bin from .storelocking import Lock @@ -317,12 +317,7 @@ class Repository: else: log_error("too small.") - if progress: - from .helpers.progress import ProgressIndicatorCounter - - pi = ProgressIndicatorCounter(step=1000, msg="Checked objects: %d", msgid="repository.check") - else: - pi = None + pi = ProgressIndicatorCounter(step=1000, msg="Checked objects: %d", msgid="repository.check") partial = bool(max_duration) assert not (repair and partial) mode = "partial" if partial else "full" @@ -369,7 +364,7 @@ class Repository: obj_corrupted = False check_object(obj) objs_checked += 1 - if pi: + if progress: pi.show(objs_checked) if obj_corrupted: objs_errors += 1 @@ -400,13 +395,13 @@ class Repository: logger.info(f"Checkpointing at key {key}.") self.store.store(LAST_KEY_CHECKED, key.encode()) if partial and now > t_start + max_duration: - if pi: + if progress: pi.finish() logger.info(f"Finished partial repository check, last key checked is {key}.") self.store.store(LAST_KEY_CHECKED, key.encode()) break else: - if pi: + if progress: pi.finish() logger.info("Finished repository check.") try: @@ -422,7 +417,7 @@ class Repository: ) except StoreObjectNotFound: # it can be that there is no "data/" at all, then it crashes when iterating infos. - if pi: + if progress: pi.finish() pass logger.info(f"Checked {objs_checked} repository objects, {objs_errors} errors.")