22 lines
1.4 KiB
Python
22 lines
1.4 KiB
Python
"""Fresh-process second readback of original and archived bytes; no runtime tests."""
|
|
from pathlib import Path
|
|
import hashlib,json
|
|
ROOT=Path(__file__).resolve().parent
|
|
manifest=json.loads((ROOT/'original-copy-manifest.json').read_text(encoding='utf-8'))
|
|
records=manifest['records']
|
|
found={str(p.relative_to(ROOT)) for p in (ROOT/'payload').rglob('*') if p.is_file()}
|
|
assert found=={r['archive'] for r in records}
|
|
def fingerprint(path):
|
|
with path.open('rb') as stream:
|
|
digest=hashlib.file_digest(stream,'sha256').hexdigest().upper()
|
|
return {'bytes':path.stat().st_size,'sha256':digest}
|
|
verified=[]
|
|
for r in records:
|
|
original=fingerprint(Path(r['source']))
|
|
archived=fingerprint(ROOT/r['archive'])
|
|
assert original==archived==r['original']==r['copy'],r['archive']
|
|
verified.append({'archive':r['archive'],**archived})
|
|
report={'result':'passed','method':'Independent fresh-process traversal, reopen both original and copied files, SHA256 file_digest and stat size, exact inventory comparison','files':len(verified),'bytes':sum(r['bytes'] for r in verified),'original_copy_manifest_sha256':fingerprint(ROOT/'original-copy-manifest.json')['sha256'],'original_manifest_sha256':manifest['original_manifest_sha256'],'verified':verified}
|
|
(ROOT/'independent-readback.json').write_text(json.dumps(report,indent=2),encoding='utf-8')
|
|
print(json.dumps({k:v for k,v in report.items() if k!='verified'},indent=2))
|