mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-10-12 06:23:23 -05:00
fix: deflate manifest on zip append path
This commit is contained in:
1 parent
954e093271
commit
3ecb72d275
2 files changed
+30
-2
No files matched your search
@@ -3471,8 +3471,10 @@ def inject_manifest(zip_path: str, manifest: dict) -> None:
|
||||
has_manifest = "manifest.json" in zf.namelist()
|
||||
|
||||
if not has_manifest:
|
||||
# Fast path: append directly
|
||||
with zipfile.ZipFile(zip_path, "a") as zf:
|
||||
# Fast path: append directly. Append mode defaults to ZIP_STORED,
|
||||
# which would leave the manifest uncompressed and give the same pack
|
||||
# two different byte layouts depending on the path taken here.
|
||||
with zipfile.ZipFile(zip_path, "a", zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.writestr("manifest.json", manifest_json)
|
||||
else:
|
||||
# Rebuild to replace existing manifest
|
||||
|
||||
@@ -5222,5 +5222,31 @@ struct BurnDriver BurnDrvneogeo = {
|
||||
self.assertEqual(only_alpha["shared-system"], {"a.bin"})
|
||||
|
||||
|
||||
def test_227_manifest_injected_compressed(self):
|
||||
"""The manifest is deflated whichever injection path runs."""
|
||||
import json as _json
|
||||
|
||||
from generate_pack import inject_manifest
|
||||
|
||||
manifest = {"files": [{"path": f"f{i}.bin"} for i in range(200)]}
|
||||
raw = _json.dumps(manifest, indent=2, ensure_ascii=False)
|
||||
sizes = []
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
for preexisting in (False, True):
|
||||
path = os.path.join(tmpdir, f"pack{int(preexisting)}.zip")
|
||||
with zipfile.ZipFile(path, "w", zipfile.ZIP_DEFLATED) as zf:
|
||||
zf.writestr("bios.bin", b"x" * 4096)
|
||||
if preexisting:
|
||||
zf.writestr("manifest.json", "{}")
|
||||
inject_manifest(path, manifest)
|
||||
with zipfile.ZipFile(path) as zf:
|
||||
info = zf.getinfo("manifest.json")
|
||||
self.assertEqual(info.compress_type, zipfile.ZIP_DEFLATED)
|
||||
self.assertEqual(_json.loads(zf.read("manifest.json")), manifest)
|
||||
sizes.append(info.compress_size)
|
||||
self.assertLess(sizes[0], len(raw))
|
||||
self.assertEqual(sizes[0], sizes[1])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user