rsc8_audio: restore writable mode before removing staging file on failure (RSC8-AUDIO-RO-CLEANUP) #724
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/724"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-24T12:57:50Z.
Claimed in the coordination issue as: RSC8-AUDIO-RO-CLEANUP https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7132063463
What and why
Hardens
_atomic_write_textintools/rsc8_audio.pywhen publishing a report fails:os.replace(tmp, path),_atomic_write_textrunsos.chmod(tmp, published_mode(path)), which copies0o444ontotmpwhen the destination report is read-only.os.replace(tmp, path)then raisesPermissionError, the cleanup handler previously calledos.remove(tmp)directly whiletmpwas still read-only, hittingPermissionError(swallowed) and leaking.rsc8_audio.<rand>.partin the output directory.os.chmod(tmp, 0o600)(guarded byexcept OSError: pass) beforeos.remove(tmp)so failed publishes over read-only targets clean up their staging file cleanly.Adds 2 synthetic regression tests in
tests/test_rsc8_audio.py(AwcAndArchiveScanTest):test_failed_replace_over_readonly_report_cleans_staging_filetest_windows_readonly_report_failure_cleans_staging_file(Windows NTFSos.replaceover0o444)Tested
Windows 11 x64 (
10.0.26100), Python3.14.7, CPU only, synthetic test inputs only (no game files). Commit01f04caccf6f75a6c0d764cf4317767795604e97.python -I tests/test_rsc8_audio.py -v:upstream/main(21625bca) with the two new tests: both fail (ran=2 failures=2 errors=0, leaking.rsc8_audio.<rand>.part);python -I tests/test_ci_registration.py: 15 tests, OK.python -I tests/test_text_write_line_endings.py: 3 tests, OK.python -I scripts/check_no_game_data.py tools/rsc8_audio.py tests/test_rsc8_audio.py,python -m compileall -q tools tests,git diff --check: exit0.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: no translator change)Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:15:45Z.
Review: APPROVED
LGTM. Clean staging file chmod/cleanup on write failure in
sc8_audio.py with cross-platform and Windows-specific unit tests in est_rsc8_audio.py.
Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T13:26:39Z.
Review: APPROVED
Audited and verified. Clean-room compliant.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T04:02:33Z.
Review: APPROVED
Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed. Only the staging/permission lines change.
AI-assisted (Claude).
Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T07:36:35Z.
Red/green: the new test fails on main (2 failed) and passes with this PR (51 passed).
Full suite with this PR merged together with seven others in one batch matches main (pytest, translator suite, ctest without the game) on Windows 11 with an RTX 4060, except xmem_write_watch, a test that depends on free host memory and has also failed on plain main.
AI-assisted (Claude Code, Claude Opus 5.5). Thank you!