File size: 1,438 Bytes
128036e | 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 27 28 29 30 31 32 33 34 35 36 37 | """Verify the payload manifest using only the Python standard library."""
import argparse
import csv
import hashlib
from pathlib import Path
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--release-root", type=Path, default=Path(__file__).resolve().parents[2])
parser.add_argument("--sizes-only", action="store_true")
args = parser.parse_args()
root = args.release_root.resolve(strict=True)
manifest = root / "code_and_checkpoints/release_metadata/FILE_MANIFEST.csv"
count = 0
total = 0
with manifest.open(encoding="utf-8", newline="") as stream:
for row in csv.DictReader(stream):
path = root / row["destination_relative_path"]
assert path.resolve(strict=True).is_relative_to(root), path
assert path.is_file() and not path.is_symlink(), path
assert path.stat().st_size == int(row["bytes"]), path
if not args.sizes_only:
with path.open("rb") as source:
actual = hashlib.file_digest(source, "sha256").hexdigest()
assert actual == row["sha256"], path
count += 1
total += int(row["bytes"])
if count % 5000 == 0:
print(f"Verified {count} payload files", flush=True)
print(f"VERIFIED files={count} logical_GiB={total / 2**30:.2f} hash_checked={not args.sizes_only}")
if __name__ == "__main__":
main()
|