Files
praxisandClaude Fable 5.2 8a24c445b0 Content pipeline and operator tools
367 files, from working commit b1a079a.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-19 01:32:48 +02:00

32 lines
2.2 KiB
Python

#!/usr/bin/env python3
"""Preserve coherent disposable-client DB2 caches before data-package changes."""
import datetime,hashlib,json,os,shutil,subprocess
from pathlib import Path
from client_installation import COPY,ROOT,running_clients,inspect_installation
def backup():
if running_clients():raise RuntimeError('Close private client normally before coherent cache backup')
identity=inspect_installation(COPY);source=COPY/'_classic_beta_/Cache/ADB'
if source.is_symlink() or not source.resolve().is_relative_to(COPY.resolve()) or not source.is_dir():raise RuntimeError('Unrecognized private DB2 cache preserved')
paths=list(source.rglob('*'))
if any(p.is_symlink() for p in paths):raise RuntimeError('Private cache contains links; no traversal')
os.umask(0o077);target=ROOT/'recovery'/('native-item-cache-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S'));target.mkdir(mode=0o700)
shutil.copytree(source,target/'ADB')
records={}
for p in paths:
if not p.is_file():continue
relative=p.relative_to(source);value=hashlib.sha256(p.read_bytes()).hexdigest()
if hashlib.sha256((target/'ADB'/relative).read_bytes()).hexdigest()!=value:raise RuntimeError('Cache copy verification failed; copies preserved')
records[str(relative)]={'bytes':p.stat().st_size,'sha256':value}
manifest={'source':str(source),'client_build':identity['version'],'git_commit':subprocess.check_output(['git','rev-parse','HEAD'],cwd=ROOT,text=True).strip(),
'files':records,'original_client_modified':False,
'restore':'Close private WowB normally; preserve its current Cache/ADB under a new recovery name, then copy this ADB directory back to that exact private Cache/ADB path. Never touch original installations, StartupFiles or CASC.'}
package=ROOT/'docs/evidence/data/item-sparse-compat/package.json'
if package.exists():
shutil.copy2(package,target/'package.json');manifest['item_package_sha256']=hashlib.sha256(package.read_bytes()).hexdigest()
(target/'manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
print('Preserved',len(records),'private DB2 cache files with matching hashes:',target.relative_to(ROOT))
return target
if __name__=='__main__':backup()