Zero all download counters in the manifest

C18: settle_download_counters wrote equal pairs (1000/1000) from a broken
manifest. Write all four counters as 0, like the from-scratch skeleton.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Krzysztof Rudnicki 2026-11-22 16:37:32 +01:00
parent 96c5a1edef
commit 889873f8dc
4 changed files with 41 additions and 13 deletions

View File

@ -213,16 +213,13 @@ def write_atomic(path: Path, text: str) -> None:
def settle_download_counters(app_state: dict) -> None:
"""Mark the download bookkeeping complete: `<X>Downloaded` == `<X>ToDownload`.
"""Zero the download bookkeeping: nothing is queued, nothing is staged.
Leaving these at their mid-download values is what made Steam discard a
StateFlags=4 manifest and resume fetching. Real installed manifests keep
these fields (they are not dropped) with the pair values equal.
StateFlags=4 manifest and resume fetching. All four go to "0", the same as
the from-scratch skeleton Steam accepted, rather than merely equal: the
older equal-pair form wrote `1000`/`1000` from a broken manifest, a value
no real install ever had.
"""
for total_key, done_key in (
("BytesToDownload", "BytesDownloaded"),
("BytesToStage", "BytesStaged"),
):
total = app_state.get(total_key)
if total is not None:
app_state[done_key] = total
for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"):
app_state[key] = "0"

View File

@ -29,7 +29,8 @@ def test_downloaded_content_finishes_the_manifest(steam, monkeypatch):
app_state = recognize.read_app_state(library.steamapps / "appmanifest_1771300.acf")
assert app_state["StateFlags"] == "4"
assert app_state["BytesDownloaded"] == app_state["BytesToDownload"]
for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"):
assert app_state[key] == "0", key
assert recognize.download_counters_settled(app_state)

View File

@ -198,3 +198,31 @@ def test_the_install_folder_is_corrected_even_when_the_download_fails(
assert cli.main(ARGV) == 1
assert recognize.read_app_state(manifest)["installdir"] == "KingdomComeDeliverance2"
def test_wrong_installdir_and_mismatched_counters_end_correct_and_zeroed(
steam, monkeypatch
):
"""C18: the live repro (installdir "... WRONG", BytesToDownload 1000,
BytesDownloaded 5) once came out as 1000/1000. The written manifest must
name the real folder, keep its files, and carry every counter at 0."""
library, install_dir = steam
manifest = library.steamapps / "appmanifest_1771300.acf"
state = recognize.read_app_state(manifest)
state.update(
installdir="KingdomComeDeliverance2 WRONG",
BytesToDownload="1000",
BytesDownloaded="5",
BytesToStage="1000",
BytesStaged="5",
)
manifest.write_text(vdf.dumps("AppState", state))
_stub_download(monkeypatch)
assert cli.main(ARGV) == 0
app_state = recognize.read_app_state(manifest)
assert app_state["installdir"] == "KingdomComeDeliverance2"
assert (install_dir / "game.pak").stat().st_size == 1000
for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"):
assert app_state[key] == "0", key

View File

@ -132,8 +132,10 @@ def test_finish_manifest_settles_download_counters(tmp_path):
)
app_state = vdf.parse(manifest_path.read_text())["AppState"]
assert app_state["BytesDownloaded"] == app_state["BytesToDownload"]
assert app_state["BytesStaged"] == app_state["BytesToStage"]
# C18: all four counters at 0, as on a from-scratch manifest. Equal-but-
# nonzero leftovers (1000/1000) are not what Steam writes for an installed app.
for key in ("BytesToDownload", "BytesDownloaded", "BytesToStage", "BytesStaged"):
assert app_state[key] == "0", key
assert app_state["StagingSize"] == "0"
# DownloadType is present on every real installed manifest -- keep it.
assert app_state["DownloadType"] == "1"