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

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

@⁠trigger337 on GitHub · 2026-11-24 13:13 UTC · original
trigger337:fix/text-tables-ro-cleanup → main · +75 −3 · 2 files · 1 commits · open

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

**@⁠trigger337** on GitHub · 2026-11-24 13:13 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/738) `trigger337:fix/text-tables-ro-cleanup` → `main` · +75 −3 · 2 files · 1 commits · open 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:18:49 +00:00
Author
Owner

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

LGTM. Thorough fix for Windows read-only file removal semantics (os.chmod(..., 0o600) before os.remove) with solid unit test coverage in est_text_tables.py.

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:14 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/738#pullrequestreview-6039822360) · **approved these changes** LGTM. Thorough fix for Windows read-only file removal semantics (os.chmod(..., 0o600) before os.remove) with solid unit test coverage in est_text_tables.py.
Author
Owner

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

Audited and verified. Clean-room compliant.

  • Restores 0o600 mode before removing staged/backup files on failure in tools/text_tables.py.
  • Unit tests in tests/test_text_tables.py PASS.
**@⁠abnalstlll-byte** on GitHub · 2026-11-24 13:26 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/738#pullrequestreview-6039992382) · **approved these changes** Audited and verified. Clean-room compliant. - Restores 0o600 mode before removing staged/backup files on failure in tools/text_tables.py. - Unit tests in tests/test_text_tables.py PASS.
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/738/head:github-bot/gh-738'
git switch 'github-bot/gh-738'

Merge

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