panxy1019's picture
Add files using upload-large-folder tool
128036e verified
Raw History Blame Contribute Delete
1.44 kB
"""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()