rtti_scan: restore write mode before unlink on replace failure (RTTI-SCAN-STAGE-CLEANUP) #798

Merged
leonida/mandy
trigger337 merged 1 commit from fix/rtti-scan-stage-cleanup into main 2026-11-28 19:34:14 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 13:58:48 +00:00

In tools/rtti_scan.py, write_report creates a temporary file and applies published_mode(path) before os.replace. If the target is read-only (e.g. 0o444), os.remove in the except BaseException block fails on Windows with PermissionError (WinError 5) if os.replace fails, leaving the temporary file behind.

Align with the repository standard:

  1. In except BaseException, restore write permissions (try: os.chmod(tmp, 0o600); except OSError: pass) before calling os.remove.
  2. Add synthetic regression test verifying PermissionError handling and cleanup on replace failure.

Tests pass (31/31 in test_rtti_scan.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

In `tools/rtti_scan.py`, `write_report` creates a temporary file and applies `published_mode(path)` before `os.replace`. If the target is read-only (e.g. 0o444), `os.remove` in the `except BaseException` block fails on Windows with `PermissionError` (WinError 5) if `os.replace` fails, leaving the temporary file behind. Align with the repository standard: 1. In `except BaseException`, restore write permissions (`try: os.chmod(tmp, 0o600); except OSError: pass`) before calling `os.remove`. 2. Add synthetic regression test verifying `PermissionError` handling and cleanup on replace failure. Tests pass (31/31 in `test_rtti_scan.py`), `scripts/check_no_game_data.py` passes cleanly. agent: yes AI-assisted: yes
tiguan26 approved these changes 2026-11-25 03:59:46 +00:00
tiguan26 left a comment

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).

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).
PierreEbele commented 2026-11-25 20:49:36 +00:00

Reviewed a6ff1f4: the staged-report cleanup when os.replace fails. I ran the PR's tests/test_rtti_scan.py: 31/31 pass on the PR tree, and on a main worktree with the PR's test file the new test fails (.rtti-*.tmp left behind) while the other 30 pass, so it tests the fix. A probe with Windows-strict unlink reproduces the leak on main and its absence on the PR, with no change to the writable-destination path. compileall and check_no_game_data are clean. Findings: none. Optional follow-up outside this PR: the same pattern (staged file given the destination's read-only mode, then cleaned up without restoring write mode) appears in classify_carve.py:118, glb_writer.py:1078 and rsc8_audio.py:1966. AI-assisted review.

Recommendation: Merge

Reviewed a6ff1f4: the staged-report cleanup when os.replace fails. I ran the PR's `tests/test_rtti_scan.py`: 31/31 pass on the PR tree, and on a main worktree with the PR's test file the new test fails (`.rtti-*.tmp` left behind) while the other 30 pass, so it tests the fix. A probe with Windows-strict unlink reproduces the leak on main and its absence on the PR, with no change to the writable-destination path. compileall and check_no_game_data are clean. Findings: none. Optional follow-up outside this PR: the same pattern (staged file given the destination's read-only mode, then cleaned up without restoring write mode) appears in classify_carve.py:118, glb_writer.py:1078 and rsc8_audio.py:1966. AI-assisted review. **Recommendation:** Merge
MoonEyes commented 2026-11-28 19:34:02 +00:00

Red/green: tests/test_rtti_scan.py fails 1 assertion on main (a read-only staged .rtti- file is left behind when replace fails under a strict remove) and passes with the PR (cloud run on main 7daa4a4).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: tests/test_rtti_scan.py fails 1 assertion on main (a read-only staged .rtti- file is left behind when replace fails under a strict remove) and passes with the PR (cloud run on main 7daa4a4). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main 7daa4a4a5 in GitHub Actions: no new failure. AI-assisted (Claude Code, Claude Opus 5.5)
OreoFR commented 2026-11-28 21:43:50 +00:00

Verified by OreoFR

  • Base: main 4a54aedcb + PR head a6ff1f4d3
  • Test: python -I tests/test_rtti_scan.py
  • Red on main: 1 failure (read-only .rtti- file left behind)
  • Green with the PR: OK (1 skipped)
  • Verdict: READY
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `4a54aedcb` + PR head `a6ff1f4d3` - Test: `python -I tests/test_rtti_scan.py` - Red on main: 1 failure (read-only .rtti- file left behind) - Green with the PR: OK (1 skipped) - Verdict: READY - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
Sign in to join this conversation.
No description provided.