Repository navigation
Tools: clean read-only staging temps after a failed report replace - #4516
bobcatchris wants to merge 4 commits into
Conversation
|
Updated to |
|
Tested What I ran:
Code review:
|
|
Tested
AI-assisted (Devin). |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 3aaeae56 on Windows 11: pytest tests/test_awc_manifest.py tests/test_bvh_index.py tests/test_navmesh_index.py tests/test_rbf0_tree.py -q -> 110 passed, 5 skipped, 16 subtests passed; git diff --check clean.
On Windows, os.chmod(tmp, 0o600) clears the read-only attribute (it sets S_IWRITE), so the four _publish/failure paths can delete a staging temp that inherited a read-only destination's mode; the OSError is suppressed as before. The added tests cover the failed-replace cleanup. No blocking issue.
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_manifest gives its mkstemp file the destination mode before os.replace. With a read-only destination the failed replace left that temp unlinkable on Windows; restore 0600 in the failure path and add a synthetic regression.
rtti_scan, shader_link_check and classify_carve give their staging file the destination's mode just before os.replace, so a read-only destination makes the replace fail and leaves a readable-only temp that Windows will not unlink. shader_link_check was worse: its finally-block unlink raised and replaced the real error. Share one discard_staged() helper in file_mode.py (clear the read-only bit, ignore cleanup errors) and add a regression per module; each one fails against main's code. rpf9_names has the same shape but stages inside a TemporaryDirectory, whose cleanup already clears read-only bits, so it needs no change.
3aaeae5 to
852f41a
Compare
|
Tested 852f41a merged with main 98fa503 on Linux (Python 3.12.16): concern - the 7 changed test files pass (awc_manifest 19, bvh_index 35, classify_carve 26, navmesh_index 31 (1 skipped), rbf0_tree 34, rtti_scan 31, shader_link_check 45); negative control with upstream/main tools/: awc_manifest, bvh_index, navmesh_index, rbf0_tree, rtti_scan each FAIL 1, shader_link_check stays OK (its test is Windows-only in effect: Linux unlink works on a read-only file, so it cannot fail here), classify_carve stays OK. Verified issue: in tests/test_classify_carve.py the new |
Appending the class after unittest.main() left the read-only replace regression unrun by python -I tests/test_classify_carve.py (26 tests, not 27); only pytest collected it. Move it above the guard so both runners see it. AI-assisted.
|
Fixed in b832130: Your caveat about AI-assisted. |
|
Tested b832130 merged with main d974c88 on Linux (Python 3.12.16) and native Windows (Python 3.13.1): concern.
|
Claimed on the coordination board: #4421 (comment)
bvh_index._publish(),navmesh_index._publish(),rbf0_tree.write_json()andawc_manifest.write_manifest()stage a report/file in the destination folder andchmodit topublished_mode(dest)beforeos.replace(). When the destination is read-only on Windows, the replace fails and theexcept/finallypath tries to unlink a temp file that now has the same read-only mode, so the temp is stranded beside the report. This is the same failuretupacfan04found in #4344; this PR applies the accepted fix to seven staged writers, through onediscard_staged()helper intools/file_mode.py.The failure path now restores mode
0600before unlink. Each tool gets one synthetic regression that injects anos.replacefailure, checks that the old bytes survive, checks that the staging file is made writable before cleanup, and checks that no.*.tmpfile remains.Scope:
awc_opus.write_file()has the same shape but is deliberately excluded because open PR #4399 changes that function (a separate heads-up is on that PR). Open PRs #4431/#3107/#3143/#2930/#4457 and the current BUILD-454 claim touch CLI/preflight paths in these files, not the write helpers.Verification (Windows 11, CPython 3.12.0, CPU only, synthetic fixtures, no game files):
python -I tests/test_bvh_index.py: 34 tests, 33 pass / 1 skip.python -I tests/test_navmesh_index.py: 28 tests, 27 pass / 1 skip.python -I tests/test_rbf0_tree.py: 34 tests, 33 pass / 1 skip.python -I tests/test_awc_manifest.py: 19/19 pass.origin/mainfail exactly the four new regressions.compileall,git diff --checkandscripts/check_no_game_data.pyon the changed files are clean.AI-assisted.
Update at
852f41ae(rebased onto7b7d73f8)Three more writers had the same shape and are now covered:
rtti_scan.write_report(),shader_link_check.write_report()andclassify_carve(whose publish step is now the namedpublish_report(), so it can be tested without a carve folder).shader_link_checkwas worse than a leftover: itsfinallydidtemporary.unlink(missing_ok=True)on a file that had just been given the destination's read-only mode, so the cleanup raised and replaced the realos.replaceerror.rpf9_names.publish_report()has the same shape but stages inside aTemporaryDirectory, whose cleanup already clears read-only bits: I wrote the regression, it passes againstmain, so there is no bug there and the module is untouched. That control is the reason the other three are in this PR and this one is not.Verification at
852f41ae(Windows 11, CPython 3.12.0, CPU only, synthetic fixtures):test_rtti_scan+test_shader_link_check+test_classify_carve+ the four earlier files = 238 passed, 4 skipped. Negative control: the three new regressions againstmain's tool files fail (the leftover temp is listed beside the report;classify_carve.publish_reportdoes not exist there yet), while therpf9_namesone passes.compileall,git diff --checkandcheck_no_game_dataon the changed files are clean.AI-assisted.