File indexing completed on 2025-01-18 09:15:42
0001 import hashlib
0002 from pathlib import Path
0003
0004
0005 def hashdir(path):
0006 digest = hashlib.md5()
0007
0008 def recurse(cur_path, digest=None):
0009 paths = cur_path.iterdir()
0010 for file_ in sorted([p for p in paths if p.is_file()]):
0011 digest.update(str(file_.relative_to(path)).encode())
0012 with open(file_, "rb") as fp:
0013 digest.update(fp.read())
0014
0015 paths = cur_path.iterdir()
0016 for dir_ in sorted([p for p in paths if p.is_dir()]):
0017 recurse(dir_, digest)
0018
0019 recurse(path, digest)
0020
0021 return digest.hexdigest()