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

Merged
leonida/mandy
trigger337 merged 1 commit from fix/native-pso-hashes-stage-cleanup into main 2026-11-28 11:09:33 +00:00

Pull request successfully merged and closed

trigger337 commented 2026-11-24 14:29:46 +00:00

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

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

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

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

Audited and verified. Applies published_mode(out) before atomic replacement and restores write permission
MoonEyes commented 2026-11-28 11:09:30 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 23 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.