From 645cbb66e44b8d0a156338e290a3b32c0ea6205e Mon Sep 17 00:00:00 2001 From: Sunil Srivatsa Date: Thu, 1 Oct 2026 14:42:22 -0700 Subject: [PATCH] fix(setup): drop an engine archive that fails to unpack get_prebuilt kept an engine archive that is not a zip (or a damaged one) together with its .done mark. download() trusts the mark, so every later run failed on the same file, even after the right archive was published; on the update path the engine was never updated. The archive and its mark are now dropped before the error propagates, as 0.1.32 does for a refused archive. --- setup.py | 8 ++++++-- tools/test_setup_pins.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 96864095..a45d39e6 100644 --- a/setup.py +++ b/setup.py @@ -1991,8 +1991,12 @@ def get_prebuilt(url_base, gpu, vision, updating=False, toolkit=13) -> Path | No download(base + asset, z, "Strata engine") tmp = eng / "_unpack" shutil.rmtree(tmp, ignore_errors=True) - with zipfile.ZipFile(z) as f: - f.extractall(tmp) + try: + with zipfile.ZipFile(z) as f: + f.extractall(tmp) + except zipfile.BadZipFile: # not a zip, or a damaged one: a kept .done mark would make + drop_archive(z) # every later run fail on it instead of downloading it again + raise meta = json.loads((tmp / "BUILD.json").read_text()) if tuple(int(x) for x in str(meta.get("version", "0")).split(".")[:3] if x.isdigit()) < MIN_ENGINE: need = ".".join(map(str, MIN_ENGINE)) diff --git a/tools/test_setup_pins.py b/tools/test_setup_pins.py index c600f692..8638fdcf 100644 --- a/tools/test_setup_pins.py +++ b/tools/test_setup_pins.py @@ -216,6 +216,21 @@ class Engine(unittest.TestCase): self.assertFalse(z.exists()) self.assertFalse(z.with_name(z.name + ".done").exists()) + def test_an_archive_that_does_not_unpack_is_not_kept(self): + """#397, for an archive that does not unpack (not a zip, or a damaged one): it kept its zip and .done mark, + so every later run failed on it, even after the right one was published.""" + with tempfile.TemporaryDirectory() as folder: # a --prebuilt folder, through the real download() + asset = Path(folder) / setup.PREBUILT_ASSET + asset.write_bytes(b"not a zip") + with self.assertRaises(zipfile.BadZipFile): + quiet(setup.get_prebuilt, folder, {"arch": 89}, "gpu") + with zipfile.ZipFile(asset, "w") as z: + z.writestr("BUILD.json", json.dumps({"version": ".".join(map(str, setup.MIN_ENGINE)), "archs": [89]})) + z.writestr(setup.EXE, b"engine") + eng, _ = quiet(setup.get_prebuilt, folder, {"arch": 89}, "gpu") + self.assertEqual(eng, self.root / "engine") + self.assertEqual((self.root / "engine" / setup.EXE).read_bytes(), b"engine") + def test_an_installed_engine_is_kept(self): (self.root / "engine" / "BUILD.json").write_text(json.dumps( {"version": ".".join(map(str, setup.MIN_ENGINE)), "archs": [89]}))