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.
The overwrite check only ran when the source was a single file. With a carve folder as the
source:
- out or --csv naming one of its streams replaced that stream with the report;
- --xml on the folder itself wrote the XML files among the streams, and the next run read
them as resources.
All three now stop with one argparse error (exit 2) before anything is decoded. Reports
beside the streams (.json, .csv) and an --xml sub-folder are still allowed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#1615's detector read the mode only at position 1, so Path.open(mode)
and tempfile.NamedTemporaryFile(mode) were not seen: three atomic report
writes (rbf0_tree, rtti_scan, world_build) still get CRLF on Windows.
They now pass newline="\n".
The test now reads the mode where each call takes it: open, io/gzip/
bz2/lzma.open and os.fdopen at position 1, Path.open and the tempfile
classes at position 0 (binary by default). It accepts only real mode
strings, and skips codecs, os, tarfile, zipfile and webbrowser opens.
Found by @undeadhuman37 in their review of #1615.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
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>
ttpf_mips scan wrote --json after reading every pool, without checking
the path: a pool given as --json (directly or found under a game folder)
was replaced by the report, and a directory or a missing folder ended in
a traceback before the report was printed. Now a --json that is a
directory or one of the pools is refused before the scan, the report is
printed first, its folder is created, and a write that still fails is
one "cannot write" line (exit 2).
rbf0_tree wrote out and --csv after the decode: either naming the source
file replaced it (write_json's atomic os.replace included), and out and
--csv on the same file kept only the CSV. Both are refused up front.
Same checks as navmesh_decode/bvh_index (same_report_path /
same_output_path). Synthetic pools and RBF0 blobs only, no game files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
awc_manifest, rsc8_audio and classify_carve stage their report in a 0600
temp file and os.replace it, so on POSIX the report ended up 0600.
rbf0_tree had its own copy of the umask(0)/umask(mask) read that file_mode
replaced (#750). All four now use file_mode.published_mode, and
tests/test_file_mode.py covers them with the other writers.
_rows() mapped each carve-folder file's offset to its path, so two files with
the same leading hex offset (000000000100-left.bin, -right.bin) both read the
last one. Rows now read the file they were built from.
write_json() opened the report for writing before serializing, so a tree too
deep to serialize (RecursionError) left the previous report truncated. The
JSON is written to a temporary file in the same folder and renamed in; a too
deep tree or an unwritable output is one line on stderr, exit 1.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each element now carries attrs_actual, children and content_count. The JSON summary reports the measured depth and child-count histograms, leaf/empty/text-only counts and parent-child edges. --csv writes one flat row per node with parent, slot and sibling columns. Tests cover sibling order, malformed close tags against the flat parser, tree-shape summary and CSV output. The docs replace the game-name sample trees with aggregate tree shape and a synthetic example.
Preserve a trailing NUL byte in a length-prefixed string instead of treating it as a terminator, overwrite per-resource XML files on a rerun rather than adding -0000 duplicates, and reject a source with no RBF0 start. Add tests for trailing NUL strings, non-finite floats and XML reruns.
Add a stdlib record/tree decoder for the measured RBF0 format. It joins 64 KiB continuations, parses the inline descriptor table, builds element/attribute/content/text trees, and writes JSON plus optional generic XML. Unknown descriptors, record types and malformed framing fail closed with a partial tree. Add synthetic tests and the measured grammar, samples and remaining unknowns to docs/rbf0.md; note the rig-set blob tree result in docs/animation.md.