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

Open
github-bot wants to merge 1 commit from github-bot/gh-798 into main AGit
Owner

@⁠trigger337 on GitHub · 2026-11-24 13:58 UTC · original
trigger337:fix/rtti-scan-stage-cleanup → main · +27 −0 · 2 files · 1 commits · open

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

**@⁠trigger337** on GitHub · 2026-11-24 13:58 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/798) `trigger337:fix/rtti-scan-stage-cleanup` → `main` · +27 −0 · 2 files · 1 commits · open 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:21:49 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 03:59 UTC · original · approved these changes

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

**@⁠tiguan26** on GitHub · 2026-11-25 03:59 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/798#pullrequestreview-6051666438) · **approved these changes** 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).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 20:49 UTC · original

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

**@⁠PierreEbele** on GitHub · 2026-11-25 20:49 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/798#issuecomment-7174239940) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/798/head:github-bot/gh-798'
git switch 'github-bot/gh-798'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-798'
git switch 'github-bot/gh-798'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-798'
git switch 'github-bot/gh-798'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-798'
git switch 'main'
git merge --squash 'github-bot/gh-798'
git switch 'main'
git merge --ff-only 'github-bot/gh-798'
git switch 'main'
git merge 'github-bot/gh-798'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.