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

Closed
leonida/mandy
trigger337 wants to merge 0 commits from fix/spirv-stubs-stage-cleanup into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

trigger337 commented 2026-11-24 14:50:00 +00:00

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

### 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
abnalstlll-byte approved these changes 2026-11-24 14:51:57 +00:00
abnalstlll-byte left a comment

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

Audited and verified. Applies published_mode(target) prior to atomic file replacement in ools/spirv_stubs.py and restores
aslan2142 commented 2026-11-24 19:50:48 +00:00

Thanks for working on this. We're closing it in favour of #924 (https://github.com/ubiquitarianism/leonida/pull/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).

Thanks for working on this. We're closing it in favour of #924 (https://github.com/ubiquitarianism/leonida/pull/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).
Sign in to join this conversation.
No description provided.