Estimate progress while rsync scans from the last backup's file count

With incremental recursion rsync only knows the total near the end, so the bar showed
no ETA for most of the backup. Save the file count as a third line of the state file
and use it as an estimate until rsync reports the real total.
This commit is contained in:
Fuxino
2026-11-02 20:56:12 +01:00
parent 5e33781974
commit ec27b8d77f
6 changed files with 142 additions and 19 deletions
+23
View File
@@ -49,6 +49,29 @@ def test_overwrite(state: Path) -> None:
assert state.read_text().splitlines()[1] == DESTINATION
def test_file_count(state: Path) -> None:
sb._write_state(None, DESTINATION, 1234)
assert state.read_text().splitlines()[2] == '1234'
assert sb._last_file_count(None) == 1234
def test_file_count_kept_when_unknown(state: Path) -> None:
write_state(state, '2026-10-01T10:00:00+02:00\n/old\n1234\n')
sb._write_state(None, DESTINATION)
assert state.read_text().splitlines()[1:] == [DESTINATION, '1234']
@pytest.mark.parametrize('text', [None, '2026-10-01T10:00:00+02:00\n/old\n', '2026-10-01T10:00:00+02:00\n/old\nx\n'])
def test_no_file_count(state: Path, text: str | None) -> None:
if text is not None:
write_state(state, text)
assert sb._last_file_count(None) == 0
def test_relative_xdg_state_home_ignored(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
monkeypatch.setenv('XDG_STATE_HOME', 'relative')
monkeypatch.setenv('HOME', str(tmp_path / 'home'))