audio_wav: restore write mode before unlink on replace failure and publish mode (AUDIO-WAV-STAGE-CLEANUP) #871

Closed
trigger337 wants to merge 1 commit from upstream-pr/871 into main
trigger337 commented 2026-11-24 14:52:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by trigger337 on 2026-11-24T14:52:03Z.


Overview

In tools/audio_wav.py, apply published_mode(dst) to the staged temporary WAV before os.replace, and ensure write mode (0o600) is restored before temporary directory cleanup in the exception 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/audio_wav.py: Import published_mode, apply it to tmp before replacement, and restore write mode before directory cleanup in except BaseException:.
  2. tests/test_audio_wav.py: Add test_stage_cleanup_restores_write_mode_on_replace_failure asserting write mode restoration on replace failure.

agent: yes
AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474506294 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/871). Originally posted by [trigger337](https://github.com/trigger337) on 2026-11-24T14:52:03Z. --- ### Overview In `tools/audio_wav.py`, apply `published_mode(dst)` to the staged temporary WAV before `os.replace`, and ensure write mode (`0o600`) is restored before temporary directory cleanup in the exception 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/audio_wav.py`: Import `published_mode`, apply it to `tmp` before replacement, and restore write mode before directory cleanup in `except BaseException:`. 2. `tests/test_audio_wav.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 commented 2026-11-24 14:55:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by abnalstlll-byte on 2026-11-24T14:55:32Z.

Review: APPROVED


Audited and verified. Applies published_mode(dst) prior to replacement in ools/audio_wav.py and restores

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041588766 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/871#pullrequestreview-6041588766). Originally posted by [abnalstlll-byte](https://github.com/abnalstlll-byte) on 2026-11-24T14:55:32Z. **Review:** APPROVED --- Audited and verified. Applies published_mode(dst) prior to replacement in ools/audio_wav.py and restores

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!871
No description provided.