Files

10 lines
2.8 KiB
Python

from pathlib import Path
import json,gzip,hashlib,subprocess,shutil
R=Path('/Users/korizatou114/Projects/とりにく工房ゲーム制作部');E=R/'docs/plans/original-completion-2026-10-02/execution/drive-offload-p23-impact-r11-20261016';verified=json.loads((E/'CLOUD_ALL_BYTES_VERIFIED.json').read_text());assert len(verified)==4 and all(x['whole_raw_readback_verified']for x in verified);m=json.loads(gzip.decompress((E/'MANIFEST.json.gz').read_bytes()));S=Path(m['source']);assert S==R/'artifacts/original-completion-2026-10-02/p23-03-native-impact-19fc3f5-r01';archive=Path(m['archive']['path']);sha=lambda p:hashlib.file_digest(p.open('rb'),'sha256').hexdigest();assert archive.is_file()and sha(archive)==m['archive']['sha256']==next(x['sha256']for x in verified if x['name']=='raw.tar.gz');assert {str(p.relative_to(S))for p in S.rglob('*')if p.is_file()}=={x['path']for x in m['files']}
for row in m['files']:
p=S/row['path'];s=p.stat();assert not p.is_symlink()and s.st_size==row['bytes']and s.st_mode&0o777==row['mode']and s.st_mtime_ns==row['mtime_ns']and sha(p)==row['sha256']
closed=subprocess.run(['/usr/sbin/lsof','-nP','+D',str(S)],capture_output=True,text=True);assert closed.returncode==1 and not closed.stdout.strip()and not closed.stderr.strip();pointer={'state':'cloud_archived','source_root':str(S),'scope':'Historical ended impact raw/layout/save/lifecycle only; stage already separately cloud archived r03, pointer included in r11; no new acceptance credit','manifest':str(E/'MANIFEST.json.gz'),'restore':str(E/'RESTORE.md'),'cloud_files':verified,'all_source_files_rehashed_before_retirement':True};(E/'SOURCE_RECHECK.json').write_text(json.dumps({'files':len(m['files']),'bytes_mode_mtime_sha_all_exact':True,'no_open_files':True,'all_cloud_archive_and_restore_bytes_verified':True},indent=2)+'\n');before=shutil.disk_usage(R).free
for row in m['files']:(S/row['path']).unlink()
for d in sorted((p for p in S.rglob('*')if p.is_dir()),key=lambda p:len(p.parts),reverse=True):d.rmdir()
assert not list(S.iterdir());(S/'CLOUD_R11.json').write_text(json.dumps(pointer,indent=2)+'\n');archive.unlink();after=shutil.disk_usage(R).free;result={'retired_root':str(S),'files':len(m['files']),'logical_bytes':sum(x['bytes']for x in m['files']),'free_before_retirement':before,'free_after_retirement':after,'delta_including_temporary_archive_removal':after-before,'temporary_archive_bytes_removed':m['archive']['bytes'],'delta_excluding_temporary_archive':after-before-m['archive']['bytes'],'free_before_preparation':m['free_before_archive'],'net_free_change_since_preparation':after-m['free_before_archive'],'archive_and_metadata_cloud_raw_readback_verified':True,'all_original_stage_pointer_bytes_preserved_in_archive':True,'current_P04_source_raw_and_cache_untouched':True,'formal_credit':0};(E/'RETIREMENT.json').write_text(json.dumps(result,indent=2)+'\n');print(result)