niqun123123 commited on
Commit
e0bc1e7
·
verified ·
1 Parent(s): 74c9217

Update code/verify_files.py

Browse files
Files changed (1) hide show
  1. verify_files.py +19 -0
verify_files.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Offline release checksum verification; executes no model code."""
3
+ import hashlib,json
4
+ from pathlib import Path
5
+ root=Path(__file__).resolve().parents[1];count=0;expected=set()
6
+ for line in (root/'SHA256SUMS').read_text().splitlines():
7
+ want,name=line.split(' ',1);f=root/name
8
+ if not f.resolve().is_relative_to(root):raise SystemExit('Invalid checksum path')
9
+ h=hashlib.sha256()
10
+ with f.open('rb') as s:
11
+ for b in iter(lambda:s.read(16*1024**2),b''):h.update(b)
12
+ if h.hexdigest()!=want:raise SystemExit('Checksum mismatch: '+name)
13
+ expected.add(name);count+=1
14
+ # HF-generated control/cache files are not model assets and may be present after download.
15
+ actual={str(f.relative_to(root)) for f in root.rglob('*') if f.is_file() and f.name!='SHA256SUMS'
16
+ and not any(x in f.relative_to(root).parts for x in {'.git','.cache','__pycache__'})}
17
+ extra=actual-expected
18
+ if extra:raise SystemExit('Unexpected files (check for stale v2 artifacts): '+str(sorted(extra)))
19
+ print(json.dumps({'passed':True,'files_verified':count},indent=2))