native_pso_hashes: restore write mode before unlink on replace failure and publish mode (NATIVE-PSO-HASHES-STAGE-CLEANUP) #845

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

@⁠trigger337 on GitHub · 2026-11-24 14:29 UTC · original
trigger337:fix/native-pso-hashes-stage-cleanup → main · +21 −0 · 2 files · 1 commits · open

Overview

In tools/native_pso_hashes.py, apply published_mode(out) before atomic replacement, and ensure write mode (0o600) is restored before unlinking in the finally block if replacement fails.

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

Changes

  1. tools/native_pso_hashes.py: Import published_mode, apply it before os.replace, and restore write permissions before unlinking.
  2. tests/test_native_pso_hashes.py: Add test_stage_cleanup_restores_write_mode_on_replace_failure asserting write permissions are restored on replace failure.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 14:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/845) `trigger337:fix/native-pso-hashes-stage-cleanup` → `main` · +21 −0 · 2 files · 1 commits · open ### Overview In `tools/native_pso_hashes.py`, apply `published_mode(out)` before atomic replacement, and ensure write mode (`0o600`) is restored before unlinking in the finally block if replacement fails. On Windows, unlinking a read-only staged file or cleaning up on `os.replace` failure causes a `PermissionError` [WinError 5], leaving stranded temporary files behind and masking underlying exceptions. ### Changes 1. `tools/native_pso_hashes.py`: Import `published_mode`, apply it before `os.replace`, and restore write permissions before unlinking. 2. `tests/test_native_pso_hashes.py`: Add `test_stage_cleanup_restores_write_mode_on_replace_failure` asserting write permissions are restored on replace failure. agent: yes AI-assisted: yes
Apply published_mode(out) to staged temporary file before replacement,
and ensure write permissions (0o600) are restored in finally block
before attempting os.unlink, preventing stranded temporary files and
masked errors on Windows when permissions are restricted.

agent: yes
AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:24:16 +00:00
Author
Owner

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

Consistent staging file permissions and atomic replacement hygiene:

  • Permission Lifecycle Guard:
    • Sets os.chmod(tmp.name, published_mode(out)) prior to os.replace.
    • In inally:, defensively restores
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 14:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/845#pullrequestreview-6041105685) · **approved these changes** ### Clean-Room Peer Review for PR #845 (native_pso_hashes: restore write mode before unlink on replace failure and publish mode) Consistent staging file permissions and atomic replacement hygiene: - **Permission Lifecycle Guard**: - Sets os.chmod(tmp.name, published_mode(out)) prior to os.replace. - In inally:, defensively restores
Author
Owner

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

Audited and verified. Applies published_mode(out) before atomic replacement and restores write permission

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 14:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/845#pullrequestreview-6041276678) · **approved these changes** Audited and verified. Applies published_mode(out) before atomic replacement and restores write permission
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/845/head:github-bot/gh-845'
git switch 'github-bot/gh-845'

Merge

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