diff options
| author | MoonEyes <ducoinbenjamin@yahoo.fr> | 2026-11-28 20:35:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-28 20:35:08 +0100 |
| commit | f459c7e0156356ea3a71b4ae3edcf6961a813d5c (patch) | |
| tree | 0a4827eef0c3d407038c691eab21598e9dc53d0d /scripts | |
| parent | e0a0e698915dc8b3fc9af19f965c1c7c0cb81f07 (diff) | |
| parent | 4895588a9339dd906d73b2f27326e60ce6237482 (diff) | |
Merge pull request #1024 from djrolfes/djrolfes/check-game-data-explicit-paths
check_no_game_data: reject invalid explicit paths (CHECK-NO-GAME-DATA-EXPLICIT-PATHS)
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/check_no_game_data.py | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py index 595fc7b1c..92097253c 100644 --- a/scripts/check_no_game_data.py +++ b/scripts/check_no_game_data.py | |||
| @@ -3,6 +3,10 @@ | |||
| 3 | python3 -I scripts/check_no_game_data.py # every file `git ls-files` lists | 3 | python3 -I scripts/check_no_game_data.py # every file `git ls-files` lists |
| 4 | python3 -I scripts/check_no_game_data.py PATH... # only these files | 4 | python3 -I scripts/check_no_game_data.py PATH... # only these files |
| 5 | 5 | ||
| 6 | Explicit PATH inputs must be regular files, not directories or symlinks. A missing, unreadable or non-regular | ||
| 7 | explicit input is reported on stderr and causes exit 2 unless another input matches game data (exit 1). | ||
| 8 | Default git enumeration still skips symlinks, submodules and files deleted from the working tree. | ||
| 9 | |||
| 6 | The extension check in .github/workflows/no-game-data.yml misses a renamed file: a DDS saved as .bin, an executable | 10 | The extension check in .github/workflows/no-game-data.yml misses a renamed file: a DDS saved as .bin, an executable |
| 7 | as .txt. This reads the first bytes of each file and matches the magic numbers of the package's formats and the | 11 | as .txt. This reads the first bytes of each file and matches the magic numbers of the package's formats and the |
| 8 | files the build extracts from it: RPF9 archives, TTPF texture pools, RAGE resources, XBCH/FSSM/DXBC shader | 12 | files the build extracts from it: RPF9 archives, TTPF texture pools, RAGE resources, XBCH/FSSM/DXBC shader |
| @@ -25,10 +29,12 @@ exits 1 if there is any. It exits 2 when a file cannot be read or git cannot lis | |||
| 25 | repository, or git not installed). Standard library only, no game files. | 29 | repository, or git not installed). Standard library only, no game files. |
| 26 | """ | 30 | """ |
| 27 | import bz2 | 31 | import bz2 |
| 32 | import errno | ||
| 28 | import gzip | 33 | import gzip |
| 29 | import io | 34 | import io |
| 30 | import lzma | 35 | import lzma |
| 31 | import os | 36 | import os |
| 37 | import stat | ||
| 32 | import subprocess | 38 | import subprocess |
| 33 | import sys | 39 | import sys |
| 34 | import tarfile | 40 | import tarfile |
| @@ -274,15 +280,19 @@ def git_error(e): | |||
| 274 | return e.strerror or str(e) | 280 | return e.strerror or str(e) |
| 275 | 281 | ||
| 276 | 282 | ||
| 277 | def check(paths, unreadable=None): | 283 | def check(paths, unreadable=None, *, explicit=False): |
| 278 | """[(path, format)] for every regular file in `paths` that starts like game data. | 284 | """[(path, format)] for every regular file in `paths` that starts like game data. |
| 279 | 285 | ||
| 280 | A file that exists but cannot be opened or read is appended to `unreadable` (when given) as (path, error).""" | 286 | Files that cannot be opened or read are appended to `unreadable` (when given) as (path, error). |
| 287 | Explicit inputs also report missing paths and non-regular entries instead of silently skipping them.""" | ||
| 281 | found = [] | 288 | found = [] |
| 282 | for path in paths: | 289 | for path in paths: |
| 283 | if os.path.islink(path) or not os.path.isfile(path): | ||
| 284 | continue # submodules, symlinks, files deleted in the working tree | ||
| 285 | try: | 290 | try: |
| 291 | if explicit: | ||
| 292 | if not stat.S_ISREG(os.lstat(path).st_mode): | ||
| 293 | raise OSError(errno.EINVAL, "not a regular file", path) | ||
| 294 | elif os.path.islink(path) or not os.path.isfile(path): | ||
| 295 | continue # submodules, symlinks, files deleted in the working tree | ||
| 286 | name = classify_file(path) | 296 | name = classify_file(path) |
| 287 | except OSError as e: | 297 | except OSError as e: |
| 288 | if unreadable is not None: | 298 | if unreadable is not None: |
| @@ -311,7 +321,7 @@ def main(argv): | |||
| 311 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) | 321 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) |
| 312 | return 2 # not 1: that is the 'game data found' code | 322 | return 2 # not 1: that is the 'game data found' code |
| 313 | unreadable = [] | 323 | unreadable = [] |
| 314 | found = check(paths, unreadable) | 324 | found = check(paths, unreadable, explicit=bool(argv)) |
| 315 | for path, name in found: | 325 | for path, name in found: |
| 316 | print(f"{display(path)}: {name}") | 326 | print(f"{display(path)}: {name}") |
| 317 | for path, e in unreadable: | 327 | for path, e in unreadable: |