move ProgressIndicatorCounter import to module level and fix progress guard pattern

This commit is contained in:
sagar 2026-03-21 23:18:12 +05:30
parent 81e11b01e8
commit 1b9805842c

View file

@ -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.")