Files
Investidor-V2/outputs/investmoz-parques-ativacao-20261016/verify-restored-files.py
T
nala cef6e201c7
tests / ci (push) Canceled after 0s
versao nrgocios 2
2026-10-16 20:11:05 +02:00

28 lines
1.4 KiB
Python

from pathlib import Path
import hashlib,json,zipfile
out=Path(__file__).resolve().parent
b=json.loads((out/'FRESH-BACKUP.json').read_text('utf-8'))
private=Path(b['private_directory']).resolve()
assert private.parent==Path('C:/Users/macbook/.config/investmoz').resolve()
p=json.loads((private/'backup-proof-private.json').read_text('utf-8'))
sha=lambda path:hashlib.sha256(path.read_bytes()).hexdigest()
assert sha(Path(p['dump_path']))==p['sha256']
assert sha(Path(p['files_path']))==p['files_sha256']
target=private/'archive-restore-verified'
assert not target.exists()
target.mkdir()
with zipfile.ZipFile(p['files_path']) as z:
assert z.testzip() is None
assert set(z.namelist())==set(p['file_hashes'])
for n,h in p['file_hashes'].items():
dest=(target/n).resolve()
assert dest.is_relative_to(target.resolve())
dest.parent.mkdir(parents=True,exist_ok=True)
data=z.read(n)
assert hashlib.sha256(data).hexdigest()==h,n
dest.write_bytes(data)
assert sha(dest)==h,n
(out/'RESTAURO-FICHEIROS.json').write_text(json.dumps({'candidate':b['candidate'],'ZIP_CRC':'passed','archive_files':len(p['file_hashes']),
'actual_archive_extraction_and_hashes':'passed','private_config_key_preserved':True,'files_sha256':p['files_sha256'],'active_changes':0},indent=2)+'\n','utf-8')
print(json.dumps({'restored_files_verified':len(p['file_hashes']),'ZIP_CRC':'passed','active_changes':0}))