The private same_output_path becomes an alias of report_paths.same_report_path,
and the import keeps same_report_path on its own line: tests/test_report_paths.py
looks for that exact line when the tool is added to SHARED.
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.
Nine archive scanners sliced every gap out of the mmap to test whether it
was all zero (`gap = m[last:s]; gap.count(0) == len(gap)`). The slice is a
copy, so a gap of N bytes allocated N bytes at once; about half of
story000.rpf (~20 GB) is non-zlib, which ends in MemoryError on a 16 GB
machine.
tools/zero_span.py compares the gap with zeros 4 MiB at a time and stops at
the first non-zero window, with the same counts (all of a gap is padding
when every byte is zero, otherwise all of it is unread). rpf9_carve,
rpf9_names, bvh_index, navmesh_index, navmesh_decode, rbf0_index,
anim_index, restofworld_index and story_index use it.
tests/test_zero_span.py checks the counts against the old expression and
runs each scanner on a 48 MiB gap under tracemalloc: 50-51 MiB heap peak
on main, under 24 MiB with this change.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.
AI-assisted (Claude), on behalf of dev-ewann.
csv.writer and csv.DictWriter default to lineterminator="\r\n", and every
one of these tools opens its report with newline="", which turns that into
CRLF on Windows and LF elsewhere: the same archive gave different report
bytes depending on the machine that exported it. awc_manifest and awc_shorts
already pin "\n" and bink_index documents why its stdout writer needs it, so
this brings the remaining 16 writers onto the same convention. A structural
test keeps new writers on it, and three tools are run end to end to check the
bytes.
Generated with Codebuff 🤖
Co-Authored-By: Codebuff <noreply@codebuff.com>
bvh_index, anim_index, gamedata_xml, gamedata_index and navmesh_decode compare
two report paths with os.path.normcase, which folds case only on Windows. On
macOS's case-insensitive APFS volume `--out o/B.json --csv o/b.json` passed and
the CSV replaced the JSON. The comparison now folds case and Unicode
normalization when the volume that will hold the path is case-insensitive
(pathconf _PC_CASE_SENSITIVE); case-sensitive volumes keep two reports.
Same fix as world_index in #1576.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").
tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
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>
rpf9_carve.py, anim_index.py, rbf0_index.py, restofworld_index.py and bvh_index.py inflated up to
the end of the archive even with --limit, so a stream that started inside the window and ended
after it was counted at its full stored size as readable while the gap before it counted as
unread: readable + zero + unread exceeded the span. On a 1.0.2.1 copy's common.rpf with
--limit 0x2000 all five reported 114.2% (one stream for 2,568 bytes that end past the window).
They now inflate only inside the window, as story_index (#712) and navmesh_index (#766) do: a
stream that doesn't end inside it is left out, and a Bink video must fit in it. Without --limit
the window is the whole archive, so nothing changes: common.rpf still gives 954 streams and 100%
in all five. bvh_index passed the window's end already but its read slices ignored it; they are
now cut at that end too.
Tests: test_rpf9_carve's LimitWindowTest and the new test_limit_window.py (anim/rbf0/restofworld/
bvh_index) put the limit inside the first of two incompressible streams; all five fail on main
and pass now (108 tests across the touched files).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit 518343b7850361a5d8046bd456e80e261a9f1e1d)
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.