Skip to content

bink_index: fail on an unlistable sub-folder instead of silently skipping its files - #4372

Open
SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/bink-index-walk-onerror
Open

SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/bink-index-walk-onerror

Conversation

@SebSilent

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: #4257 (comment)

What and why

bink_index.py scan_target indexes a directory with os.walk(target) and no onerror. os.walk silently
skips a sub-folder it cannot list, so the index reported the remaining files and exited 0, hiding an
incomplete directory. Reproduced on 03b09a0: a directory with a.bik in the root and sub/b.bik reports
128 unread bytes; after chmod 000 on sub it reports 64, exit 0. The walk now passes an onerror that
re-raises, which main()'s existing except OSError around scan_target turns into one
bink_index: error: cannot read ... line and exit 2. Same os.walk/onerror completeness gap as #4277 / #4342 /
#4355. Open #4015 touches the scan's sorting/formatting (lines 191+), not the walk's error handling.

Tested

Linux, Python 3.14.10, CPU only, no game files (synthetic Bink 2 streams).

  • New tests/test_bink_index.py::TestCommandLine::test_unlistable_subfolder_is_a_clean_error_not_a_silent_skip:
    chmod 000 a sub-folder, bink.main returns 2 with a bink_index: error: line and no traceback (skips when
    the folder is still listable, e.g. running as root or on Windows). Red on the base: exit 0. Green: whole file 20 OK.
  • python -m compileall -q make_game.py tools tests, git diff --check clean.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (no translator rule changed)
  • Docs updated for any new flag, tool or workflow. (no new flag)

AI-assisted (Tacit).

@Kam471 Kam471 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran this at 8b04cdd7 on Windows 11: python -I tests/test_bink_index.py -> 20 tests, OK (1 skipped); git diff --check clean.

An unlistable sub-folder now fails the Bink index instead of silently skipping its files, matching the other walk fixes; the synthetic index tests pass. No blocking issue.

@Alpaca-exe

Copy link
Copy Markdown
Contributor

Tested 8b04cdd7 on Windows 11, Python 3.11.9 (CPU only, no game files): pass (with platform os.chmod skip + mocked os.walk check)

  • python -I tests/test_bink_index.py -v: 19/20 passed, 1 skipped (test_unlistable_subfolder_is_a_clean_error_not_a_silent_skip skipped on Windows because os.chmod(0o000) leaves directories listable).
  • python -I scripts/check_no_game_data.py: pass.
  • Simulated os.walk onerror callback (PermissionError passed to onerror via mock.patch): bink_index.main(['fake_dir']) exits cleanly with code 2 and single-line bink_index: error: cannot read sub: Access is denied (no traceback).

AI-assisted.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of 8b04cdd: an unlistable subfolder now fails the tool instead of silently dropping its files. 20 tests OK (1 skipped); compileall and diff check clean.

AI-assisted (OpenCode).

@SebSilent

Copy link
Copy Markdown
Contributor Author

Right, chmod 0o000 is a no-op on the runner. Added a second regression that forces the same PermissionError through os.scandir so the guard is exercised on Windows and under root; the chmod case stays as the real-filesystem check.

Red/green on the new case: fails against main's bink_index.py (scan completes, exit 0), passes with the onerror fix. Full file: 21 tests OK. Rebased on d0835dd, head now e9382fe.

@kapitche

Copy link
Copy Markdown
Contributor

Tested e9382fe merged with main 98fa503 on Linux (WSL2) Python 3.12.16 and native Windows 11 Python 3.13.1: pass.

  • python -I tests/test_bink_index.py: Linux 21 OK; Windows 21 OK (skipped=1, the chmod test, which self-skips there by design; the scandir-mock test runs).
  • Negative control: tools/bink_index.py restored from main with the PR tests kept. Linux: FAILED (failures=2, both new tests). Windows: FAILED (failures=1, the scandir-mock test; the chmod one is the skip). Restored from the PR -> OK.
  • Diff read: os.walk(target, onerror=_walk_error) re-raises, and main() turns the OSError into one bink_index: error: cannot read <dir>: ... line with exit 2, no traceback. No concerns.
  • The Windows run used a throwaway worktree of the PR head merged with main, since removed.

@DenRakEiw

Copy link
Copy Markdown
Contributor

Tested head 27c2b16c412c02ec4770a179a259fe9a0bb1bfdd on Windows 11 / Python 3.12.10.

  • Trial-merge (origin/main): clean (git merge --no-commit --no-ff FETCH_HEAD exited 0; git diff --cached --check clean).
  • Tests:
    • python -I tests/test_bink_index.py -v: 22 ran — 21 passed, 1 skipped (test_unlistable_subfolder_is_a_clean_error_not_a_silent_skip, skipped on Windows because os.chmod(..., 0o000) keeps directories listable; the scandir-mocked test_unlistable_subfolder_is_a_clean_error_when_chmod_is_not_enough and test_unlistable_folder_cannot_hide_an_input_from_the_out_check both passed)
    • python -I tests/test_text_write_line_endings.py -v: 3 passed (0 failed)
  • Code read: tools/bink_index.py adds _walk_error as onerror to both os.walk calls (in scan_target and the --out overwrite check in main) so unlistable subdirectories fail closed with exit code 2 and one stderr line instead of silently omitting entries or bypassing the overwrite guard.

AI-assisted review (Gemini 4 Neon).

@SebSilent
SebSilent force-pushed the fix/bink-index-walk-onerror branch from 27c2b16 to 675daed Compare November 23, 2026 06:06
@SebSilent

Copy link
Copy Markdown
Contributor Author

Follow-up from the tracker note about the --out overwrite walk: pushed 675daed on top of e9382fe.

The guard that decides whether --out names an existing input ran its own walk over the target without
onerror. (reasoning elided) So on main an input inside a folder the walk cannot list sails through the check and then gets
truncated by the report write. (reasoning elided) Reproduced before the fix: rc 0, the .bin under the locked folder replaced by the
report.

The guard now uses the same _walk_error as the scan, so it stops the run with one bink_index: error: line and
exit 2 before anything is scanned or written. (reasoning elided) The new test forces the PermissionError through os.scandir
(same trick as the earlier Windows/root nit) and also asserts scan_target is never reached and the input bytes
are still intact afterwards.

Also rebased onto current main (d974c88a), no conflicts, still just tools/bink_index.py plus the test file.

Tested here:

  • python -I tests/test_bink_index.py: 22 OK (20 on main, plus the two new cases).
  • Red check on the rebased tree: swapping in main's tools/bink_index.py gives FAILED (failures=3), putting my
    version back gives OK.
  • python -m compileall -q tools tests make_game.py clean, python -I scripts/check_no_game_data.py silent exit 0,
    git diff --check clean.

AI-assisted.

@sds-228 sds-228 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review of 675daed: still clean at the new head. An unlistable subfolder still fails the tool rather than silently dropping its files, with expanded fixture coverage. 22 tests OK (1 skipped); compileall and diff check clean.

AI-assisted (OpenCode).

SebSilent added 2 commits November 23, 2026 04:03
…ping its files

os.walk() without onerror skips a directory it cannot list, so indexing a
tree with a locked folder reported the rest and exited 0. scan_target now
passes an onerror that re-raises, and main's existing OSError handler turns
it into one error line and exit 2.

Two regressions: the chmod case (skips where chmod is not enforced) and a
scandir-forced case that runs on every platform.
The guard walks the target to see whether --out names an existing input. Without onerror an unlistable sub-folder was skipped, so an input inside it passed the check and got truncated by the report write (verified on main: rc 0, input replaced). The guard walk now uses the same _walk_error as the scan and reports one error line with exit 2 before anything is scanned or written.
@SebSilent
SebSilent force-pushed the fix/bink-index-walk-onerror branch from 675daed to 64082b9 Compare November 23, 2026 07:03
@SebSilent

Copy link
Copy Markdown
Contributor Author

Rebased on current main (3faac557), head is now 64082b96. No content change: tools/bink_index.py and tests/test_bink_index.py are identical to what I pushed as 675daed, python -I tests/test_bink_index.py still runs 22 tests OK, compileall clean, scripts/check_no_game_data.py silent.

Heads up for anyone who tested the earlier refs: e9382fe and 27c2b16c4 are no longer on the branch, the code behind them is unchanged, only the base moved.

AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 64082b9 merged with main 3faac55 on Linux (WSL2), Python 3.12.16: pass.

  • tests/test_bink_index.py: 22 tests OK, none skipped (non-root user, so the chmod 000 case really ran). tests/test_bink_names.py and tests/test_bink_play.py also OK.
  • Negative control: with main's tools/bink_index.py, test_bink_index.py fails 3 of 22 (the unlistable-subfolder tests, e.g. main returns 0 where the test expects 2).
  • Read the diff: the os.walk onerror hook is applied to both walks (the scan and the --out overwrite guard); the guard walk's OSError is caught in main() and gives exit 2, the scan's is caught by the existing handler.

@KkelebekK

Copy link
Copy Markdown

Reviewed and tested 64082b96 (on top of main 3faac557, so the merge is a fast-forward), CPU only: Linux, Python 3.14, no game data. Looks good.

Notes, none blocking:

  • Refuse partial Bink indexes when a directory cannot be listed #3973 makes the same scan_target change and conflicts with this PR in both files. This PR is a superset, since it also covers the --out guard, so one of the two should be closed.
  • The PR body is stale. It still says "whole file 20 OK" and only describes the scan_target walk, not the --out guard change or the two os.scandir regression tests.
  • Out of scope, but the same gap is still in bink_names.py. Its own --out guard walk and the --mount folder walk have no onerror. A --mount folder with a mode 300 sub-folder holding the --out file still gets that input overwritten, rc 0, on this head.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants