46 lines
1.9 KiB
Python
46 lines
1.9 KiB
Python
|
|
#!/usr/bin/env python3
|
||
|
|
"""Verify preserved artifacts against the original relocation inventory."""
|
||
|
|
from pathlib import Path
|
||
|
|
import argparse
|
||
|
|
import hashlib
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
||
|
|
parser.add_argument('--repository', type=Path,
|
||
|
|
default=Path(__file__).resolve().parents[1])
|
||
|
|
args = parser.parse_args()
|
||
|
|
records = json.loads((Path(__file__).resolve().parent /
|
||
|
|
'archive/move_manifest.json').read_text())
|
||
|
|
original = Path('/Users/tboudreaux/Programming/4DSTAR/MeanField')
|
||
|
|
failures, count, size = [], 0, 0
|
||
|
|
for move in records['moves']:
|
||
|
|
destination = args.repository / Path(move['destination']).relative_to(original)
|
||
|
|
for item in move['entries']:
|
||
|
|
path = destination if item['path'] == '.' else destination / item['path']
|
||
|
|
if item['kind'] == 'directory':
|
||
|
|
good = path.is_dir() and not path.is_symlink()
|
||
|
|
elif item['kind'] == 'symlink':
|
||
|
|
good = path.is_symlink() and os.readlink(path) == item['target']
|
||
|
|
else:
|
||
|
|
count += 1
|
||
|
|
size += item['bytes']
|
||
|
|
good = path.is_file() and not path.is_symlink()
|
||
|
|
if good:
|
||
|
|
digest = hashlib.sha256()
|
||
|
|
with path.open('rb') as stream:
|
||
|
|
for block in iter(lambda: stream.read(1024 * 1024), b''):
|
||
|
|
digest.update(block)
|
||
|
|
good = path.stat().st_size == item['bytes'] and digest.hexdigest() == item['sha256']
|
||
|
|
if not good:
|
||
|
|
failures.append(str(path))
|
||
|
|
print(json.dumps({'files': count, 'bytes': size, 'failed_paths': failures,
|
||
|
|
'all_preserved': not failures}, indent=2))
|
||
|
|
raise SystemExit(bool(failures))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
main()
|