Datasets:
File size: 2,038 Bytes
7ff74f6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/usr/bin/env python3
"""Read-only: sha256 of every file that must change (local paths / host names), then which files embed those digests."""
import hashlib, json, collections as C
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
H = Path('${LOCAL}/simulation-workspace/runs/hf-release-20261120')
res = json.load(open(H / 'work/scan.json'))
def sha(p):
h = hashlib.sha256()
with open(p, 'rb') as f:
for b in iter(lambda: f.read(1 << 22), b''): h.update(b)
return h.hexdigest()
seed = [x for x in res if x['n_abs'] or x['hosts']]
with ThreadPoolExecutor(16) as ex:
digs = list(ex.map(lambda x: sha(Path(x['root']) / x['rel']), seed))
d2f = {d: x['rel'] for d, x in zip(digs, seed)}
changed = {x['rel'] for x in seed}; byrel = {x['rel']: x for x in res}
# closure: a file embedding the digest of a changed file must change too
frontier = set(d2f); rounds = 0; edges = C.defaultdict(set)
while frontier:
rounds += 1; new = set()
for x in res:
for h in x['hashes']:
if h in frontier:
edges[x['rel']].add(d2f[h])
if x['rel'] not in changed: new.add(x['rel'])
frontier = set()
if new:
with ThreadPoolExecutor(16) as ex:
ds = list(ex.map(lambda r: sha(Path(byrel[r]['root']) / r), sorted(new)))
for r, d in zip(sorted(new), ds): d2f[d] = r; frontier.add(d)
changed |= new
print('round', rounds, 'new', len(new))
bin_ = [r for r in changed if not byrel[r]['text']]
print('changed total', len(changed), 'binary among them', len(bin_), C.Counter(Path(r).suffix for r in bin_))
print('GB', round(sum(byrel[r]['size'] for r in changed) / 1e9, 2), 'roots', C.Counter('shm' if byrel[r]['root'].startswith('/dev') else 'disk' for r in changed))
print('files with hash edges', len(edges), 'edges', sum(map(len, edges.values())))
json.dump(dict(changed=sorted(changed), digest_of={v: k for k, v in d2f.items()}, edges={k: sorted(v) for k, v in edges.items()}), open(H / 'work/graph.json', 'w'))
|