bink_index: close mkstemp fd on fdopen error, restore mode before unlink, and publish mode on Windows (BINK-INDEX-STAGE-CLEANUP) #740

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

@⁠trigger337 on GitHub · 2026-11-24 13:15 UTC · original
trigger337:fix/bink-index-stage-cleanup → main · +89 −6 · 2 files · 1 commits · open

In tools/bink_index.py:

  1. _temp_stream: if os.fdopen(fd, "wb") raises an exception, fd was leaked. If an error occurred while streaming bytes, unlinking could fail if file mode was touched. Added try...except BaseException: os.close(fd); raise and guaranteed write-mode restoration (os.chmod(..., 0o600)) before os.unlink in both exception handling and cleanup callback.
  2. _publish_text: skipped os.chmod(staged.name, published_mode(destination)) on Windows (if os.name != "nt":) because unlinking a read-only temp file in finally fails on Windows with PermissionError. By ensuring os.chmod(staged.name, 0o600) before os.unlink in finally, Windows now safely inherits published_mode(destination), and temporary staging files are never leaked on failed writes/replacements.
  3. Added regression tests covering fd closure on fdopen failure, cleanup callback behavior, read-only temp file removal with strict Windows unlinking simulation, and Windows published mode application.

agent: yes
AI-assisted: yes

**@⁠trigger337** on GitHub · 2026-11-24 13:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/740) `trigger337:fix/bink-index-stage-cleanup` → `main` · +89 −6 · 2 files · 1 commits · open In `tools/bink_index.py`: 1. `_temp_stream`: if `os.fdopen(fd, "wb")` raises an exception, `fd` was leaked. If an error occurred while streaming bytes, unlinking could fail if file mode was touched. Added `try...except BaseException: os.close(fd); raise` and guaranteed write-mode restoration (`os.chmod(..., 0o600)`) before `os.unlink` in both exception handling and cleanup callback. 2. `_publish_text`: skipped `os.chmod(staged.name, published_mode(destination))` on Windows (`if os.name != "nt":`) because unlinking a read-only temp file in `finally` fails on Windows with PermissionError. By ensuring `os.chmod(staged.name, 0o600)` before `os.unlink` in `finally`, Windows now safely inherits `published_mode(destination)`, and temporary staging files are never leaked on failed writes/replacements. 3. Added regression tests covering fd closure on fdopen failure, cleanup callback behavior, read-only temp file removal with strict Windows unlinking simulation, and Windows published mode application. agent: yes AI-assisted: yes
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:18:54 +00:00
Author
Owner

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

Audited and verified. Clean-room compliant.

  • Properly closes temporary file descriptor on os.fdopen failure in tools/bink_index.py.
  • Restores 0o600 file mode before unlinking to prevent Windows PermissionErrors on read-only files.
  • Applies published_mode across all platforms, with regression coverage in tests/test_bink_index.py.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/740#pullrequestreview-6039966391) · **approved these changes** Audited and verified. Clean-room compliant. - Properly closes temporary file descriptor on os.fdopen failure in tools/bink_index.py. - Restores 0o600 file mode before unlinking to prevent Windows PermissionErrors on read-only files. - Applies published_mode across all platforms, with regression coverage in tests/test_bink_index.py.
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/740/head:github-bot/gh-740'
git switch 'github-bot/gh-740'

Merge

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