Skip to content

bvh_index: refuse a report folder that is a file before the scan (BUILD-880) - #3085

Closed
TreXito wants to merge 1 commit into
ItsNotRexed:mainfrom
TreXito:fix/bvh-index-report-folder
Closed

TreXito wants to merge 1 commit into
ItsNotRexed:mainfrom
TreXito:fix/bvh-index-report-folder

Conversation

@TreXito

@TreXito TreXito commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as BUILD-880, second half only: #3047 (comment)

The first half of BUILD-880 (tools/world_lights_paths.py truncating the previous report before --entities is read) is already handled by #2748, so it isn't in this PR.

What and why

bvh_index.py only found a file blocking the --out/--csv folder after the scan. Before this change, on main 16282101:

$ python -I tools/bvh_index.py <dir> --out blocker.txt/report.json
...summary...
  File "tools/bvh_index.py", line 347, in _make_parent
FileExistsError: [Errno 17] File exists: '.../blocker.txt'          (exit 1)

$ python -I tools/bvh_index.py <dir> --csv blocker.txt/deep/r.csv
NotADirectoryError: [Errno 20] Not a directory: '.../blocker.txt/deep'   (exit 1)

The whole scan is lost at that point. On levels.rpf that is the long part of the run.

Changes in tools/bvh_index.py:

  • _file_in_the_way(path): walks up from the report's folder to the nearest path that exists and returns it if it is a file. main() runs this check next to the existing --out/--csv path checks, before the scan, and exits 2 through ap.error: <file> is not a folder, so --out <path> cannot be written. Missing folders are still created, as test_missing_report_folder_is_created expects.
  • write_outputs is wrapped in except OSError. A write that still fails (no permission, a full disk, the folder replaced after the check) prints bvh_index: error: cannot write the report: <error> and exits 2, the same code as an unreadable archive, instead of a traceback with exit 1. The summary is already on stdout by then.

Output bytes don't change for any run that succeeds.

Overlaps

#2684 (staged _publish writes) also edits this file. I placed the new helper above main(), next to same_output_path, so the two PRs don't touch the same lines. I applied #2684's diff on top of this branch with git apply --3way: it applied cleanly and all 34 combined test_bvh_index.py tests pass. With both merged, a failed write leaves the old report intact (#2684) and ends in one line with exit 2 (this PR). #2468, #2348 and #2726 also apply cleanly on top.

Tests

New tests in tests/test_bvh_index.py, all synthetic (no game files):

  • test_report_folder_that_is_a_file_is_rejected_before_the_scan: --out file/x.json, --out file/deep/x.json and --csv file/x.csv each exit 2 with the message. scan_dir is mocked to fail if it gets called, and the blocking file is left unchanged.
  • test_report_write_error_exits_2_without_a_traceback: with the preflight bypassed, the real write fails, main() returns 2 with one line and no traceback, and the summary is still printed.
  • test_new_report_folders_under_a_folder_are_still_allowed.

Without the fix in tools/bvh_index.py, the new tests fail: 3 failures and 2 errors.

Ran (Linux, CPU only, no GPU needed):

  • python -I tests/test_bvh_index.py: 29 OK on Python 3.12.13 and 3.14.4.
  • python -m compileall -q make_game.py tools tests: OK.
  • python -I on each of test_text_write_line_endings, test_tool_startup, test_tool_stdout_encoding, test_resource_hygiene, test_report_paths, test_report_path_case and test_navmesh_index: all OK.

Not tested on Windows. The check uses only os.path (exists, isdir, dirname, abspath), and Windows also reports a path under a file as non-existent.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…LD-880)

A file where the --out or --csv folder (or a folder above it) has to be
was only found after the scan: _make_parent raised FileExistsError or
NotADirectoryError, the run ended in a traceback with exit 1, and the scan
was lost. main() now checks it with the other path checks, before the
scan, and exits 2 with one line. A report write that still fails (no
permission, a full disk, the folder replaced meanwhile) exits 2 with one
line instead of a traceback; the summary is already printed by then.

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

TreXito commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #3107. @0xTehuti claimed BUILD-880 first, and #3107 makes the same bvh_index change with tests (see #3047).

@TreXito TreXito closed this Nov 22, 2026
@Hanioe2

Hanioe2 commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 0088efc7 on Windows build 26200 with Python 3.14.7, using the independent verification claim. The comparison base was 16282101.

python -I tests/test_bvh_index.py passed 29 tests on the PR head and 26 on its base. Seven additional CLI checks passed:

  • For both --out and --csv, paths directly under a file and paths nested deeper under it returned exit 2 before the scan on the PR head. All four returned exit 1 with a traceback on the base. The blocking file kept its original bytes.

  • For each flag, an exclusive Windows handle on an existing report reproduced a real write error. The PR head returned exit 2 with a report-write message, printed the scan summary, and preserved the locked report. The base returned exit 1 with a PermissionError traceback.

  • New nested report directories were created and the resulting JSON and CSV both parsed with one synthetic row.

CPU-only synthetic fixtures. No game files.

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.

2 participants