| 35 | |
| 36 | |
| 37 | def identity(path): |
| 38 | resolved = Path(path).resolve(strict=True) |
| 39 | info = resolved.stat() |
| 40 | if not stat.S_ISREG(info.st_mode) or not os.access(str(resolved), os.X_OK): |
| 41 | raise ValueError("not an executable regular file: " + str(resolved)) |
| 42 | digest = hashlib.sha256() |
| 43 | with resolved.open("rb") as stream: |
| 44 | for block in iter(lambda: stream.read(1024 * 1024), b""): |
| 45 | digest.update(block) |
| 46 | return {"path": str(resolved), "sha256": digest.hexdigest(), "bytes": info.st_size} |
| 47 | |
| 48 | |
| 49 | def save_json(path, value): |