spirv_stubs: restore write mode before remove on replace failure and publish mode (SPIRV-STUBS-STAGE-CLEANUP) #866

Closed
github-bot wants to merge 1 commit from gh-pr/866/head into gh-pr/866/base
Owner

@⁠trigger337 on GitHub · 2026-11-24 14:50 UTC · original
trigger337:fix/spirv-stubs-stage-cleanup → main · +27 −5 · 2 files · 1 commits · closed without merging

Overview

In tools/spirv_stubs.py, apply published_mode(target) to the staged temporary stub before atomic replacement (replacing the POSIX-only shutil.copymode), and ensure write mode (0o600) is restored before removing in the exception block if replacement fails.

On Windows, unlinking/removing a read-only staged file or cleaning up on os.replace failure causes a PermissionError [WinError 5], leaving stranded temporary files behind.

Changes

  1. tools/spirv_stubs.py: Import published_mode, apply it to staged before replacement, and restore write mode before os.remove in except BaseException:.
  2. tests/test_spirv_stubs.py: Add test_stage_cleanup_restores_write_mode_on_replace_failure asserting write mode restoration on replace failure.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 14:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/866) `trigger337:fix/spirv-stubs-stage-cleanup` → `main` · +27 −5 · 2 files · 1 commits · closed without merging ### Overview In `tools/spirv_stubs.py`, apply `published_mode(target)` to the staged temporary stub before atomic replacement (replacing the POSIX-only `shutil.copymode`), and ensure write mode (`0o600`) is restored before removing in the exception block if replacement fails. On Windows, unlinking/removing a read-only staged file or cleaning up on `os.replace` failure causes a `PermissionError` [WinError 5], leaving stranded temporary files behind. ### Changes 1. `tools/spirv_stubs.py`: Import `published_mode`, apply it to `staged` before replacement, and restore write mode before `os.remove` in `except BaseException:`. 2. `tests/test_spirv_stubs.py`: Add `test_stage_cleanup_restores_write_mode_on_replace_failure` asserting write mode restoration on replace failure. agent: yes AI-assisted: yes
Apply published_mode(target) to temporary stub file before atomic replacement,
and restore write permission (0o600) before removing in exception block
when replace fails, preventing Windows PermissionError [WinError 5] and
stranded temporary files.

agent: yes
AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:25:21 +00:00
github-bot closed this pull request 2026-11-26 09:25:22 +00:00
Author
Owner

@⁠abnalstlll-byte on GitHub · 2026-11-24 14:51 UTC · original · approved these changes

Audited and verified. Applies published_mode(target) prior to atomic file replacement in ools/spirv_stubs.py and restores

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 14:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/866#pullrequestreview-6041522531) · **approved these changes** Audited and verified. Applies published_mode(target) prior to atomic file replacement in ools/spirv_stubs.py and restores
Author
Owner

@⁠aslan2142 on GitHub · 2026-11-24 19:50 UTC · original

Thanks for working on this. We're closing it in favour of #924 (#924), which makes the same tool change.

  • The new test asserts st_mode & 0o777 == 0o600, but on Windows os.chmod only clears the read-only flag and os.stat reports 0o666, so the Windows check job would fail on it.
  • #924 uses the same published_mode / chmod 0o600 / remove cleanup as navmesh_index and bvh_index, and its test checks that no .tmp file is left behind, on every OS.
  • Your separate try around the chmod and the remove is better than #924's single block: if the chmod fails, the staged file is still removed. It's worth carrying over into #924, with credit to you.
  • The claim timing was noted; the maintainers pick the fix that's ready to merge.

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

**@⁠aslan2142** on GitHub · 2026-11-24 19:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/866#issuecomment-7142671129) Thanks for working on this. We're closing it in favour of #924 (https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/924), which makes the same tool change. - The new test asserts `st_mode & 0o777 == 0o600`, but on Windows `os.chmod` only clears the read-only flag and `os.stat` reports `0o666`, so the Windows `check` job would fail on it. - #924 uses the same `published_mode` / `chmod 0o600` / remove cleanup as `navmesh_index` and `bvh_index`, and its test checks that no `.tmp` file is left behind, on every OS. - Your separate `try` around the chmod and the remove is better than #924's single block: if the chmod fails, the staged file is still removed. It's worth carrying over into #924, with credit to you. - The claim timing was noted; the maintainers pick the fix that's ready to merge. AI-assisted (Claude Code, Claude Opus 5.5).

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.