rdna2spirv: restore write mode before unlink on replace failure and publish mode on Windows in write_index (RDNA2SPIRV-INDEX-STAGE-CLEANUP) #803

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

@⁠trigger337 on GitHub · 2026-11-24 14:00 UTC · original
trigger337:fix/rdna2spirv-index-stage-cleanup → main · +35 −2 · 2 files · 1 commits · open

In tools/rdna2spirv.py, write_index creates a temporary file and previously skipped applying published_mode on Windows because os.unlink in the except BaseException block fails with PermissionError (WinError 5) if replace_retry fails on read-only destinations.

Align with the repository standard:

  1. In except BaseException, restore write permissions (try: os.chmod(tmp, 0o600); except OSError: pass) before calling os.unlink.
  2. Apply published_mode(path) unconditionally so Windows outputs receive proper permissions instead of keeping NamedTemporaryFile's default 0o600 mode.
  3. Add synthetic regression tests verifying PermissionError handling and Windows published_mode application.

Tests pass (11/11 in test_rdna2spirv_index_write.py), scripts/check_no_game_data.py passes cleanly.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 14:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/803) `trigger337:fix/rdna2spirv-index-stage-cleanup` → `main` · +35 −2 · 2 files · 1 commits · open In `tools/rdna2spirv.py`, `write_index` creates a temporary file and previously skipped applying `published_mode` on Windows because `os.unlink` in the `except BaseException` block fails with `PermissionError` (WinError 5) if `replace_retry` fails on read-only destinations. Align with the repository standard: 1. In `except BaseException`, restore write permissions (`try: os.chmod(tmp, 0o600); except OSError: pass`) before calling `os.unlink`. 2. Apply `published_mode(path)` unconditionally so Windows outputs receive proper permissions instead of keeping `NamedTemporaryFile`'s default `0o600` mode. 3. Add synthetic regression tests verifying `PermissionError` handling and Windows `published_mode` application. Tests pass (11/11 in `test_rdna2spirv_index_write.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:22:03 +00:00
Author
Owner

@⁠MoonEyes on GitHub · 2026-11-24 14:37 UTC · original

Reviewed on native Windows 11 (Python 3.14.0) and on WSL (Python 3.14.4). The diff only touches write_index; translation is unaffected.

  • python -I tests/test_rdna2spirv_index_write.py: 11 OK on Windows (1 POSIX skip), 11 OK on Linux.
  • Red before green: dropping the chmod(tmp, 0o600) fails the read-only cleanup test; restoring the os.name guard fails the Windows publish test.
  • If both replace_retry and the cleanup chmod fail, the original exception still propagates and no staging file is left.

Two notes:

  1. On main, Windows cleanup already works: the staged file was never chmod'ed there, so it stayed writable. The new read-only cleanup test passes against main's rdna2spirv.py on Windows, and a real run with a 0o444 destination raises WinError 5 and leaves no staging file on both main and this branch. Also, NamedTemporaryFile reports 0o666 on Windows, not 0o600. So on Windows the change is effectively a no-op. It is fine for consistency with #775/#777/#780/#786/#791, but the description overstates it.
  2. test_publish_applies_published_mode_on_windows only asserts that some chmod happened. Asserting that the first call targets the .index-*.tmp file with published_mode(path) would pin the behavior. Likewise, assertRaises(OSError) in the cleanup test would also pass if an error from unlink or chmod surfaced instead of the replace error.

AI-assisted review (Claude Code).

**@⁠MoonEyes** on GitHub · 2026-11-24 14:37 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/803#issuecomment-7134681891) Reviewed on native Windows 11 (Python 3.14.0) and on WSL (Python 3.14.4). The diff only touches write_index; translation is unaffected. - python -I tests/test_rdna2spirv_index_write.py: 11 OK on Windows (1 POSIX skip), 11 OK on Linux. - Red before green: dropping the chmod(tmp, 0o600) fails the read-only cleanup test; restoring the os.name guard fails the Windows publish test. - If both replace_retry and the cleanup chmod fail, the original exception still propagates and no staging file is left. Two notes: 1. On main, Windows cleanup already works: the staged file was never chmod'ed there, so it stayed writable. The new read-only cleanup test passes against main's rdna2spirv.py on Windows, and a real run with a 0o444 destination raises WinError 5 and leaves no staging file on both main and this branch. Also, NamedTemporaryFile reports 0o666 on Windows, not 0o600. So on Windows the change is effectively a no-op. It is fine for consistency with #775/#777/#780/#786/#791, but the description overstates it. 2. test_publish_applies_published_mode_on_windows only asserts that some chmod happened. Asserting that the first call targets the .index-*.tmp file with published_mode(path) would pin the behavior. Likewise, assertRaises(OSError) in the cleanup test would also pass if an error from unlink or chmod surfaced instead of the replace error. AI-assisted review (Claude Code).
Author
Owner

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

Approving. Merged into current main (9f9a7c5) with no conflicts. tests/test_rdna2spirv_index_write.py passes (11 tests), and the full translator suite gives 491 files / 6,312 tests with only test_int32_to_f64 failing, the same baseline failure as main here (Linux, Python 3.13).

On Windows os.chmod only toggles the read-only bit, so applying published_mode there is harmless. On the failure path, making the temp file writable again before unlink is what lets a read-only temp be removed on Windows, and the OSError guard keeps cleanup best-effort.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 19:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/803#pullrequestreview-6063765114) · **approved these changes** Approving. Merged into current main (9f9a7c5) with no conflicts. `tests/test_rdna2spirv_index_write.py` passes (11 tests), and the full translator suite gives 491 files / 6,312 tests with only `test_int32_to_f64` failing, the same baseline failure as main here (Linux, Python 3.13). On Windows `os.chmod` only toggles the read-only bit, so applying `published_mode` there is harmless. On the failure path, making the temp file writable again before `unlink` is what lets a read-only temp be removed on Windows, and the `OSError` guard keeps cleanup best-effort. AI-assisted (Claude).
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/803/head:github-bot/gh-803'
git switch 'github-bot/gh-803'

Merge

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