diff options
| author | Romain PINSOLLE <romain.pins@gmail.com> | 2026-11-24 16:11:40 +0100 |
|---|---|---|
| committer | Romain PINSOLLE <romain.pins@gmail.com> | 2026-11-24 16:11:40 +0100 |
| commit | 074e53069faa592b9fcabc47f128a383dcdc0f82 (patch) | |
| tree | 6fd06977ceadcdf3bf0ebf9318c7c000384961c1 /scripts | |
| parent | a28927849adb4e40dfdec8c32fb6758dcd205a37 (diff) | |
check_no_game_data: exit 2 when git cannot list the files (CHECK-NO-GAME-DATA-GIT-ERROR)
Outside a repository, or with git missing from PATH, the default mode died with a traceback and exit 1,
which is the "game data found" code. It now prints one line naming git and the error, and exits 2.
Tests cover a missing git, a folder outside any repository, and the unchanged results inside a repository.
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/check_no_game_data.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/scripts/check_no_game_data.py b/scripts/check_no_game_data.py index a5b65e242..bccee5e68 100644 --- a/scripts/check_no_game_data.py +++ b/scripts/check_no_game_data.py | |||
| @@ -21,7 +21,8 @@ under a budget per checked file (64 MiB expanded, 10,000 members), so a zip bomb | |||
| 21 | reported as archives that can't be checked. | 21 | reported as archives that can't be checked. |
| 22 | 22 | ||
| 23 | Prints one line per match, `<path>: <format>` (`<format> in <archive> (<member>)` for a match inside an archive), and | 23 | Prints one line per match, `<path>: <format>` (`<format> in <archive> (<member>)` for a match inside an archive), and |
| 24 | exits 1 if there is any. Standard library only, no game files. | 24 | exits 1 if there is any. It exits 2 when a file cannot be read or git cannot list the tracked files (outside a |
| 25 | repository, or git not installed). Standard library only, no game files. | ||
| 25 | """ | 26 | """ |
| 26 | import bz2 | 27 | import bz2 |
| 27 | import gzip | 28 | import gzip |
| @@ -257,6 +258,14 @@ def tracked_files(root): | |||
| 257 | return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p] | 258 | return [os.path.join(root, p) for p in out.decode("utf-8", "surrogateescape").split("\0") if p] |
| 258 | 259 | ||
| 259 | 260 | ||
| 261 | def git_error(e): | ||
| 262 | """One line on why git could not list the files: the first line git printed, or the OS error.""" | ||
| 263 | if isinstance(e, subprocess.CalledProcessError): | ||
| 264 | lines = (e.stderr or b"").decode("utf-8", "replace").splitlines() | ||
| 265 | return next((line.strip() for line in lines if line.strip()), f"exit status {e.returncode}") | ||
| 266 | return e.strerror or str(e) | ||
| 267 | |||
| 268 | |||
| 260 | def check(paths, unreadable=None): | 269 | def check(paths, unreadable=None): |
| 261 | """[(path, format)] for every regular file in `paths` that starts like game data. | 270 | """[(path, format)] for every regular file in `paths` that starts like game data. |
| 262 | 271 | ||
| @@ -285,7 +294,14 @@ def display(path): | |||
| 285 | 294 | ||
| 286 | 295 | ||
| 287 | def main(argv): | 296 | def main(argv): |
| 288 | paths = argv or tracked_files(os.getcwd()) | 297 | if argv: |
| 298 | paths = argv | ||
| 299 | else: | ||
| 300 | try: | ||
| 301 | paths = tracked_files(os.getcwd()) | ||
| 302 | except (OSError, subprocess.CalledProcessError) as e: | ||
| 303 | print(f"check_no_game_data: cannot list the tracked files with git: {git_error(e)}", file=sys.stderr) | ||
| 304 | return 2 # not 1: that is the 'game data found' code | ||
| 289 | unreadable = [] | 305 | unreadable = [] |
| 290 | found = check(paths, unreadable) | 306 | found = check(paths, unreadable) |
| 291 | for path, name in found: | 307 | for path, name in found: |