Skip to content

bvh_index: a sub-folder the report-path check cannot list is an error, not a silent skip (BUILD-1374) - #4729

Open
rafaelpssz wants to merge 1 commit into
ItsNotRexed:mainfrom
rafaelpssz:fix/walk-bvh_index
Open

rafaelpssz wants to merge 1 commit into
ItsNotRexed:mainfrom
rafaelpssz:fix/walk-bvh_index

Conversation

@rafaelpssz

@rafaelpssz rafaelpssz commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

BUILD-1374, one tool per PR as the item asks (claim).

What

tools/bvh_index.py main() checks, when the target is a folder, that --out/--csv isn't a file inside it before writing. That walk (os.walk(a.target), ~line 499) has no onerror, so a sub-folder it can't list is skipped in silence. A report path inside such a folder passes the check and the file gets overwritten.

Now onerror calls ap.error: it names the flag and the folder and exits 2 before anything is written.

Error, not a logged skip: this walk is a safety check, for the same reason as in bink_names.

The folder scan itself (scan_dir) is not touched. The open #4431 rewrites it, with unlistable folders reported as logged skips. This PR changes only the overwrite check, which no open PR edits. #3143, #3107, #3098, #4556 and #4431 edit nearby lines of main(), so whichever lands second may need a small rebase.

Tests

  • New: ScanTest.test_overwrite_check_fails_on_an_unlistable_sub_folder in tests/test_bvh_index.py, with os.scandir raising PermissionError for one sub-folder.
  • On the old code the new test fails ("SystemExit not raised"). With the fix, tests/test_bvh_index.py passes 35 tests with 1 skipped. The skipped test is POSIX-only and was skipped before this change too. compileall and git diff --check are clean.
  • Synthetic folders only, no game files.

Thanks

By @rafaelpssz, with Claude Code (AI-assisted).

… a silent skip (BUILD-1374)

When --out or --csv names an existing file and the target is a folder,
main() walks the folder to make sure the report would not overwrite an
input. That os.walk had no onerror, so a sub-folder it could not list
was skipped and the check passed without having looked inside it: a
report file in that folder could be overwritten.

This is a safety check, so a folder it cannot list is an error: the
walk's onerror calls ap.error, which names the flag and the folder and
exits 2 before anything is written, like the other "would overwrite"
refusals. The scan itself (scan_dir, glob on main) is left to ItsNotRexed#4431,
which turns it into an os.walk whose unlistable folders are logged and
make the run exit 1 as incomplete.

The test forces os.scandir to raise PermissionError for one sub-folder
(chmod cannot lock a folder on Windows) and checks the exit code, the
folder in the message and that the existing report is untouched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 c8f263917 on Windows 11: pytest tests/test_bvh_index.py -q -> 34 passed, 1 skipped, 2 subtests passed; git diff --check clean.

A sub-folder the report-path check cannot list is now an error (exit 2) rather than a silent skip, with the existing report tests unchanged. No blocking issue.

@SweatierKey

Copy link
Copy Markdown
Contributor

Tested c8f26391 on Linux (x86_64, Python 3.13.5): pass (code read + unit tests).

What I ran:

  • git diff --check main...HEAD: clean.
  • python3 -m unittest tests/test_bvh_index.py: 35/35 OK (including test_overwrite_check_fails_on_an_unlistable_sub_folder, confirming exit code 2, error message naming the locked folder, no traceback, and preserved existing report).

Code review:

  • Passing onerror=unlistable to os.walk in the overwrite-check loop of tools/bvh_index.py ensures an unlistable sub-folder fails closed instead of being silently skipped and risking an overwrite of a report file inside it.

@Atomic258

Copy link
Copy Markdown

Tested head c8f263917100f66e600f68a494e5cfe90c5cba17 on Windows 11, Python 3.15.2 (same SHA as the earlier runs above).

  • python -I tests/test_bvh_index.py: 35 tests, OK (1 skipped — the POSIX-only test, skipped before this change too)
  • python -m compileall -q tools tests and git diff --check origin/main...HEAD: clean
  • Red control: git checkout origin/main -- tools/bvh_index.py, re-ran — test_overwrite_check_fails_on_an_unlistable_sub_folder fails with "SystemExit not raised" (1 failure of 35), matching the PR description. Restored the PR file; re-run green, worktree clean.

All pass.

AI-assisted (Devin).

@dcastell1

Copy link
Copy Markdown
Contributor

Code read + CPU tests, c8f2639: pass (test_bvh_index: 35).

@memorypressure

Copy link
Copy Markdown

Verified on Linux: all 35 tests pass under python -I and test_bink_names is unaffected. Same shape as the #4728 fix in the sibling tool, including the Windows-portable mock test; the closure correctly attributes the error to the flag whose walk failed. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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.

6 participants