Keep the progress bar estimate when the last file count is exceeded

When a backup has more files than the last one, estimate the total from the files rsync has found so far,
capped at 99% until the scan ends, instead of falling back to "(scanning)".
This commit is contained in:
Fuxino
2026-11-14 11:08:21 +01:00
parent 68b6d77f30
commit 2c7233ce45
3 changed files with 33 additions and 10 deletions
+22 -3
View File
@@ -303,12 +303,31 @@ class TestProgressBar:
assert capsys.readouterr().err == \
'\r[#######-----------------------] ~25% 1,000/~4,000 files 2.00M copied ETA ~0:01:30\033[K'
def test_estimate_exceeded(self, capsys: pytest.CaptureFixture[str]) -> None:
def test_estimate_exceeded(self, monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]) -> None:
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
bar = sb._ProgressBar(estimate=1000)
# More files than in the last backup: back to plain scanning
# More files than in the last backup: estimate from the files found so far
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=500/2000)')
assert capsys.readouterr().err == '\r1,500 files checked 2.00M copied (scanning)\033[K'
assert capsys.readouterr().err == \
'\r[######################--------] ~75% 1,500/~2,000 files 2.00M copied ETA ~0:00:10\033[K'
def test_estimate_capped_while_scanning(self, monkeypatch: pytest.MonkeyPatch,
capsys: pytest.CaptureFixture[str]) -> None:
monkeypatch.setattr(sb, 'get_terminal_size', lambda: os.terminal_size((100, 24)))
bar = sb._ProgressBar(estimate=1000)
# All files found so far are checked, but rsync may still find more
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=0/2000)')
assert bar.total is None
assert ' ~99% 2,000/~2,000 files 2.00M copied ETA ~0:00:00\033[K' in capsys.readouterr().err
def test_no_estimate_without_last_count(self, capsys: pytest.CaptureFixture[str]) -> None:
bar = sb._ProgressBar()
# The files found so far are only a guess at the total near the end of the scan
assert bar.update(' 2.00M 25% 1.47MB/s 0:00:02 (xfr#1, ir-chk=0/2000)')
assert capsys.readouterr().err == '\r2,000 files checked 2.00M copied (scanning)\033[K'
def test_real_total_replaces_estimate(self, capsys: pytest.CaptureFixture[str]) -> None:
bar = sb._ProgressBar(estimate=4000)