[PR #738] text_tables: restore write mode before removing staged and backup files (TEXT-TABLES-RO-CLEANUP) #777

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

📋 Pull Request Information

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

Base: main ← Head: fix/text-tables-ro-cleanup


📝 Commits (1)

  • 1e97f80 text_tables: restore write mode before removing staged and backup files (TEXT-TABLES-RO-CLEANUP)

📊 Changes

2 files changed (+75 additions, -3 deletions)

View changed files

📝 tests/test_text_tables.py (+58 -0)
📝 tools/text_tables.py (+17 -3)

📄 Description

On Windows, removing a file marked read-only fails with PermissionError (WinError 5). In tools/text_tables.py:

  1. When destination was read-only, os.chmod(tmp, published_mode(dest)) sets tmp to read-only mode. If a subsequent write fails, rollback attempted os.remove(tmp), which failed on Windows and leaked staging files.
  2. When replacing an existing read-only file, the original destination was backed up to .text_tables-old-*. Upon successful completion, os.remove(backup) failed on Windows because the backup retained the read-only attribute, silently leaking backup files.
  3. If an unexpected BaseException (e.g., interrupt or crash) occurred during the stage/swap loop, rollback was not executed. Catching BaseException guarantees that staged and backup files are cleaned up and original files restored before re-raising non-OSErrors.

Restores write permissions (os.chmod(..., 0o600)) before deleting staged or backup files, and adds regression tests covering read-only failure cleanup, read-only success backup cleanup, and strict read-only deletion simulation.

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/738 **Author:** [@trigger337](https://github.com/trigger337) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/text-tables-ro-cleanup` --- ### 📝 Commits (1) - [`1e97f80`](https://github.com/ubiquitarianism/leonida/commit/1e97f80a85ae051f3855ed39df20c7d7ab3911b1) text_tables: restore write mode before removing staged and backup files (TEXT-TABLES-RO-CLEANUP) ### 📊 Changes **2 files changed** (+75 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_text_tables.py` (+58 -0) 📝 `tools/text_tables.py` (+17 -3) </details> ### 📄 Description On Windows, removing a file marked read-only fails with PermissionError (WinError 5). In `tools/text_tables.py`: 1. When destination was read-only, `os.chmod(tmp, published_mode(dest))` sets `tmp` to read-only mode. If a subsequent write fails, rollback attempted `os.remove(tmp)`, which failed on Windows and leaked staging files. 2. When replacing an existing read-only file, the original destination was backed up to `.text_tables-old-*`. Upon successful completion, `os.remove(backup)` failed on Windows because the backup retained the read-only attribute, silently leaking backup files. 3. If an unexpected BaseException (e.g., interrupt or crash) occurred during the stage/swap loop, rollback was not executed. Catching BaseException guarantees that staged and backup files are cleaned up and original files restored before re-raising non-OSErrors. Restores write permissions (`os.chmod(..., 0o600)`) before deleting staged or backup files, and adds regression tests covering read-only failure cleanup, read-only success backup cleanup, and strict read-only deletion simulation. 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#777
No description provided.