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.
This commit is contained in:
1 parent
3f8f333e92
commit
645cbb66e4
2 files changed
+21
-2
No files matched your search
@@ -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))
|
||||
|
||||
@@ -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"<html>not a zip</html>")
|
||||
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]}))
|
||||
|
||||
Reference in new issue
Block a user