| #!/usr/bin/env python3 | |
| # Copyright 2026 The Fuchsia Authors | |
| # | |
| # Licensed under a BSD-style license <LICENSE-BSD>, Apache License, Version 2.0 | |
| # <LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0>, or the MIT | |
| # license <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your option. | |
| # This file may not be copied, modified, or distributed except according to | |
| # those terms. | |
| """Fetch and SHA-256-verify the pinned google/zerocopy dogfood snapshot.""" | |
| import hashlib | |
| import json | |
| from pathlib import Path | |
| import sys | |
| import tarfile | |
| import urllib.request | |
| def main() -> int: | |
| if len(sys.argv) != 3: | |
| sys.stderr.write(f"usage: {sys.argv[0]} <pin.json> <dest_dir>\n") | |
| return 2 | |
| pin_path = Path(sys.argv[1]) | |
| dst = Path(sys.argv[2]) | |
| pin = json.loads(pin_path.read_text(encoding="utf-8")) | |
| rev = pin["revision"] | |
| want = pin["archive_sha256"] | |
| url = f"https://github.com/{pin['repository']}/archive/{rev}.tar.gz" | |
| req = urllib.request.Request(url, headers={"User-Agent": "anneal-ci/1.0"}) | |
| data = urllib.request.urlopen(req, timeout=180).read() | |
| got = hashlib.sha256(data).hexdigest() | |
| if got != want: | |
| sys.stderr.write( | |
| f"zerocopy dogfood tarball sha256 mismatch: {got} != {want}\n" | |
| ) | |
| return 1 | |
| tgz = dst.parent / "zerocopy-dogfood.tar.gz" | |
| tgz.write_bytes(data) | |
| dst.mkdir(parents=True, exist_ok=True) | |
| with tarfile.open(tgz, "r:gz") as tf: | |
| prefix = f"zerocopy-{rev}/" | |
| for member in tf.getmembers(): | |
| if not member.name.startswith(prefix): | |
| continue | |
| rel = member.name[len(prefix):] | |
| if not (rel == "zerocopy" or rel.startswith("zerocopy/")): | |
| continue | |
| member.name = rel | |
| tf.extract(member, dst, filter="data") | |
| tgz.unlink() | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) |