File size: 1,234 Bytes
a7335ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Build a deterministic zip of the verified IceCube release directory.

usage: python3 -I make_zip.py <release_dir> <out.zip> <manifest.sha256>
Entries: every file listed in the manifest, sorted, fixed timestamp, mode 0644.
"""
import hashlib, sys, zipfile
from pathlib import Path

src, out, manifest = Path(sys.argv[1]), Path(sys.argv[2]), Path(sys.argv[3])
want = {}
for line in manifest.read_text().splitlines():
    digest, name = line.split(None, 1)
    want[name.strip().removeprefix("./")] = digest
on_disk = sorted(str(p.relative_to(src)) for p in src.rglob("*") if p.is_file())
assert on_disk == sorted(want), (set(on_disk) ^ set(want))
with zipfile.ZipFile(out, "w", compression=zipfile.ZIP_DEFLATED, compresslevel=9) as zf:
    for name in sorted(want):
        data = (src / name).read_bytes()
        assert hashlib.sha256(data).hexdigest() == want[name], name
        info = zipfile.ZipInfo(name, date_time=(2021, 1, 26, 0, 0, 0))
        info.compress_type = zipfile.ZIP_DEFLATED
        info.external_attr = 0o100644 << 16
        info.create_system = 3
        zf.writestr(info, data, compress_type=zipfile.ZIP_DEFLATED, compresslevel=9)
print(out, out.stat().st_size, hashlib.sha256(out.read_bytes()).hexdigest())