Datasets:
| #!/usr/bin/env python3 | |
| """Verify every SHA-256 digest listed in metadata/checksums.sha256.""" | |
| from __future__ import annotations | |
| import hashlib | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| CHECKSUMS = ROOT / "metadata" / "checksums.sha256" | |
| def sha256(path: Path) -> str: | |
| digest = hashlib.sha256() | |
| with path.open("rb") as handle: | |
| for chunk in iter(lambda: handle.read(1024 * 1024), b""): | |
| digest.update(chunk) | |
| return digest.hexdigest() | |
| def main() -> None: | |
| verified = 0 | |
| for line_number, line in enumerate( | |
| CHECKSUMS.read_text(encoding="utf-8").splitlines(), start=1 | |
| ): | |
| if not line.strip(): | |
| continue | |
| expected, relative_path = line.split(" ", maxsplit=1) | |
| path = ROOT / Path(relative_path) | |
| if not path.is_file(): | |
| raise FileNotFoundError(f"Missing file listed at line {line_number}: {path}") | |
| actual = sha256(path) | |
| if actual != expected: | |
| raise ValueError( | |
| f"Checksum mismatch for {relative_path}: expected {expected}, got {actual}" | |
| ) | |
| verified += 1 | |
| print(f"Verified {verified} release files.") | |
| if __name__ == "__main__": | |
| main() | |