Any other unlistable folder is left to the scan, which names it and exits 1
with an incomplete report, so a second run is no longer refused just because
the first one wrote the report.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 #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>
The overwrite refusals (source archive, carve manifest, input files, a folder as destination, --out equal to --csv)
were already in place. What remained of BUILD-454: a report path under a file or in a folder that can't be written
ended the run in a NotADirectoryError or PermissionError traceback, after the whole scan. report_path_problem()
now creates and probes each report's folder before scanning and argparse refuses the path with the reason; an
OSError while writing after the scan (a full disk, a folder removed since) is one stderr line and exit 2, and the
atomic publish still leaves no partial file. Two tests: a destination under a file is refused before scan_dir is
called; a write failure after the scan returns 2 with the message and no report. Both fail on main.
AI-assisted (Claude Code, Claude Fable 5.1).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GDgoLQVYG7p8mvxkwBroVz
bvh_index, navmesh_index and rbf0_tree give the staging file the destination mode before os.replace. On Windows a read-only destination makes the replace fail and leaves a temp that cannot be unlinked. Restore 0600 in the failure path before unlink, and add regressions that pin the mode reset, old bytes and no leftovers.
write_outputs opened the JSON and CSV reports with open(dest, "w"), which empties
the previous report before the new one is serialized: a TypeError in json.dump, a
full disk or Ctrl+C left a truncated file where an intact report used to be.
Each report is now written to a NamedTemporaryFile in the destination folder
(.bvh_index-*.tmp / .navmesh_index-*.tmp), given published_mode(dest) and swapped
in with os.replace. On any exception the staging file is removed and the
existing report is left untouched.
Tests: PublishTest in tests/test_bvh_index.py and tests/test_navmesh_index.py
(JSON serialization failure, CSV write failure, KeyboardInterrupt, published_mode
applied to the staged file, POSIX bits kept). All synthetic, no game data.
AI-assisted.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Archive scans only report fill for complete node buffers. Carved chunks exposed header metadata but recorded partial fill counts, so the same data produced different measurements.
With a carve directory as the target, --out (and bvh_index's --csv) could
replace <dir>/index.json (or a carved payload through a hard link) and
exit 0; #1264 only compared the report with the target path itself, which
covers an .rpf target but not a directory. bvh_index also lost the report
to a FileNotFoundError in a missing folder, and ended in a PermissionError
traceback when the report path was an existing directory.
Refuse report paths that resolve to the carve manifest or an input file,
create the report folder before writing, and reject a directory report
path; tests cover each shape on synthetic fixtures.
test_world_census, test_bvh_index, test_world_index and
test_audit_shader4_regs call the tools' main(), which prints a JSON summary
or report; run as scripts (as CI does) that is about 280 lines of noise
around the results. A setUpModule per file redirects stdout; the tests that
check the output already redirect it themselves.
scan_rpf() built the fill histogram when the declared node bytes fit in the
stream's full size, but it only has the bytes it kept under --max-inflate. A
capped stream gave {'total': 0}, which looks like a BVH with no filled nodes.
The histogram now needs the declared bytes to be in what was kept; a capped
stream has no fill key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The indexer treated the pre-header wrapper words as the root and labelled the real header fields as counts. Parse the documented XboxBvh4Header fields, decode root node pointers, and document the runtime node and leaf layouts while keeping the dehydrated packed stream open.
bvh_index, page_index, story_index, navmesh_index and psin_index:
- --limit 0 meant "no limit" (0 is falsy) and a negative --limit scanned
nothing and still exited 0 with an empty index. --limit must now be at
least 1 and --start 0 or more; argparse rejects anything else (rc 2).
- An empty .rpf crashed in mmap ("cannot mmap an empty file") and a file
shorter than the header word crashed in struct.unpack_from. bvh, page and
story now treat both as an archive with no streams.
- bvh_index directory mode: one bad archive no longer aborts the scan and
loses the results of the others; it is reported and skipped.
- A --start past the end of the archive is a one-line error (rc 2) instead
of a traceback (bvh also checked nothing and reported a negative span).
- page_index checks the output extension before the scan, not after it.
Docs: the accepted ranges and the empty-archive behaviour are written next
to each tool's usage in docs/{bvh,navmesh,page_directory,psin,story}.md.
Tests: synthetic cases for each tool; they fail on main and pass here.
Index the three *_bvh4 RPF9 packs with the fixed carver and record the measured stream/byte composition. Add tools/bvh_index.py for the 0x81020006 header family (tag + 0x140 + 64*n == end), with synthetic tests. No game data, keys or carved payloads are included.