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

Open
opened 2026-11-26 20:19:01 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/740
Author: @trigger337
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/bink-index-stage-cleanup


📝 Commits (1)

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

📊 Changes

2 files changed (+89 additions, -6 deletions)

View changed files

📝 tests/test_bink_index.py (+57 -0)
📝 tools/bink_index.py (+32 -6)

📄 Description

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


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/740 **Author:** [@trigger337](https://github.com/trigger337) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bink-index-stage-cleanup` --- ### 📝 Commits (1) - [`070df2d`](https://github.com/ubiquitarianism/leonida/commit/070df2d53ac0aa38bce3770f287bb8c3f3944045) bink_index: close mkstemp fd on fdopen error, restore mode before unlink, and publish mode on Windows (BINK-INDEX-STAGE-CLEANUP) ### 📊 Changes **2 files changed** (+89 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_bink_index.py` (+57 -0) 📝 `tools/bink_index.py` (+32 -6) </details> ### 📄 Description 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#779
No description provided.