| 1 | |
| 2 | |
| 3 | |
| 4 | import hashlib |
| 5 | import pathlib |
| 6 | import subprocess |
| 7 | import sys |
| 8 | |
| 9 | root = pathlib.Path(__file__).resolve().parent |
| 10 | result = subprocess.run( |
| 11 | ['git', 'lfs', 'ls-files', '--long', '--null'], cwd=root, |
| 12 | check=True, stdout=subprocess.PIPE, |
| 13 | ) |
| 14 | failed = [] |
| 15 | count = 0 |
| 16 | for entry in result.stdout.decode('utf-8').split('\0'): |
| 17 | if not entry: |
| 18 | continue |
| 19 | digest, marker, name = entry.split(' ', 2) |
| 20 | path = root / name |
| 21 | if not path.is_file(): |
| 22 | failed.append(name + ': missing') |
| 23 | continue |
| 24 | actual = hashlib.sha256() |
| 25 | with path.open('rb') as stream: |
| 26 | for chunk in iter(lambda: stream.read(1024 * 1024), b''): |
| 27 | actual.update(chunk) |
| 28 | if actual.hexdigest() != digest: |
| 29 | failed.append(name + ': hash mismatch (run git lfs pull)') |
| 30 | count += 1 |
| 31 | if count == 0: |
| 32 | failed.append('No LFS files found') |
| 33 | print(f'Checked {count} files; {len(failed)} errors.') |
| 34 | for error in failed: |
| 35 | print(error) |
| 36 | sys.exit(bool(failed)) |