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

Merged
trigger337 merged 1 commit from upstream-pr/798 into main 2026-11-28 19:34:14 +00:00
trigger337 commented 2026-11-24 13:58:48 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T13:58:48Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5473565436 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/798). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T13:58:48Z. --- 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 commented 2026-11-25 03:59:46 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-25T03:59:46Z.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6051666438 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/798#pullrequestreview-6051666438). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-25T03:59:46Z. **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).
PierreEbele commented 2026-11-25 20:49:36 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T20:49:36Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7174239940 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/798#issuecomment-7174239940). Originally posted by [PierreEbele](https://github.com/PierreEbele) on 2026-11-25T20:49:36Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T19:34:02Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7244641074 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/798#issuecomment-7244641074). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T19:34:02Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T21:43:50Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246229798 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/798#issuecomment-7246229798). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T21:43:50Z. --- **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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!798
No description provided.