[PR #4903] [Other] a read-only folder no longer stops a model delete on Windows (Fix #4089) #5242

Open
opened 2026-11-07 16:33:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/4903
Author: @XiaoBinGan
Created: 11/1/2026
Status: 🔄 Open

Base: main ← Head: fix/remove-read-only-windows


📝 Commits (1)

  • 6b4fcda Fix #4089: a read-only folder no longer stops a model delete on Windows

📊 Changes

2 files changed (+80 additions, -1 deletions)

View changed files

📝 tools/strata_mcp.py (+13 -1)
📝 tools/test_strata_mcp.py (+67 -0)

📄 Description

Problem and result

Deleting a model on Windows stopped at the first read-only folder and left the rest of the pack on disk (#4089):

Some files could not be removed: rt: [WinError 5] Accès refusé: 'C:\Users\<user>\Documents\Strata\mtp\rt';
iq2_xs: [WinError 5] Accès refusé: 'C:\Users\<user>\Documents\Strata\packs\iq2_xs\tokenizer'

Both paths were empty folders with the Windows ReadOnly attribute set. tools/strata_mcp.py strata_remove()
deletes a model's plan with shutil.rmtree(p, onerror=_rmtree_ignore_missing), and the hook only returned for
FileNotFoundError, re-raising everything else. Windows refuses RemoveDirectory on a folder with
FILE_ATTRIBUTE_READONLY, even when it is empty, so the first such path became a failure and the delete stopped
there.

Reproduced on main (c62d5e3a) on Windows 11, Python 3.11.16: a temporary Strata folder with a read-only empty
folder and a read-only file inside another folder, deleted through Tools.strata_remove():

before: failed=["rt: [WinError 5] ...'\\mtp\\rt\\note.txt'", "tokenizer: [WinError 5] ...'\\packs\\iq2_xs\\tokenizer'"]
        folder_still_there=True
after:  failed=[]  folder_still_there=False  (both cases)

(The message text is in Chinese on this machine by its locale; the code is WinError 5, ERROR_ACCESS_DENIED.)

#4089 — the report, with the exact folders and the WinError 5 lines. A focused fix to an existing error hook, not a
new feature, so no separate scope agreement was asked for.

Approach

  • _rmtree_ignore_missing() still passes a path that is already gone (FileNotFoundError), so a folder a
    background scan emptied meanwhile keeps working.
  • On PermissionError it now clears the read-only attribute (os.chmod(path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)) and retries exactly that one path with the same function shutil.rmtree gave it (that is what
    pip's rmtree_errorhandler does for the same Windows rule). func is the operation that failed, so the retry is
    the same operation on the same path, not a deletion of the whole tree.
  • Any other OSError, and a retry that fails again, still count as a failure exactly as before: this does not hide
    a locked file (antivirus, a running process).
  • The permission bits 0o700 are the ones the hook needs on any platform; on Windows os.chmod maps them to the
    single read-only bit.

Validation

Passed: the new regression test on the branch, python -m pytest tools/test_strata_mcp.py -q -k RemoveReadOnly
(Python 3.11.16, Windows 11): 1 passed, 52 deselected. It builds a read-only empty folder, a read-only file in
another folder, and the model's config, and asserts strata_remove() reports failed: [] and that all three are
gone.

Passed: the module's full suite on the branch, python -m pytest tools/test_strata_mcp.py -q: 1 failed, 52
passed
— the one failure is MacCatalog::test_deepseek_on_a_mac_offers_the_two_sets_that_were_run_with_the_mac_words,
which already fails on unmodified main in this checkout (it predates UD-IQ1_S/M being offered on a Mac) and is
unrelated to this change.

Failed: the same new test on unmodified main (only the hook reverted, the test kept):
AssertionError: Lists differ: ["rt: [WinError 5] ...", "tokenizer: [WinError 5] ..."] != [] at
tools/test_strata_mcp.py:998. That is the A/B: the test pins the change.

Not run: a real model delete from the desktop app on this machine (it needs a multi-GB installed pack), and this
test's run on Linux/macOS (the read-only attribute is a Windows rule; the test skips there).

Limits

  • Only PermissionError is retried. A denial from ACLs or a folder held open by another process still fails, as it
    should; the fix is specifically the Windows read-only attribute.
  • The change is cross-platform by construction but was only measured on Windows 11. On POSIX the condition is rare
    (unlink/rmdir rights come from the parent), so the POSIX branch is untested here.
  • The retry clears the attribute on the one path being removed. Files inside a read-only folder are handled one by
    one as shutil.rmtree descends, which is what func gives the hook.

🔄 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/Niko1221/Strata/pull/4903 **Author:** [@XiaoBinGan](https://github.com/XiaoBinGan) **Created:** 11/1/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/remove-read-only-windows` --- ### 📝 Commits (1) - [`6b4fcda`](https://github.com/Niko1221/Strata/commit/6b4fcda7521058d3c43e72a4082bd7d584b72807) Fix #4089: a read-only folder no longer stops a model delete on Windows ### 📊 Changes **2 files changed** (+80 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `tools/strata_mcp.py` (+13 -1) 📝 `tools/test_strata_mcp.py` (+67 -0) </details> ### 📄 Description ## Problem and result Deleting a model on Windows stopped at the first read-only folder and left the rest of the pack on disk (#4089): ```text Some files could not be removed: rt: [WinError 5] Accès refusé: 'C:\Users\<user>\Documents\Strata\mtp\rt'; iq2_xs: [WinError 5] Accès refusé: 'C:\Users\<user>\Documents\Strata\packs\iq2_xs\tokenizer' ``` Both paths were empty folders with the Windows `ReadOnly` attribute set. `tools/strata_mcp.py` `strata_remove()` deletes a model's plan with `shutil.rmtree(p, onerror=_rmtree_ignore_missing)`, and the hook only returned for `FileNotFoundError`, re-raising everything else. Windows refuses `RemoveDirectory` on a folder with `FILE_ATTRIBUTE_READONLY`, even when it is empty, so the first such path became a failure and the delete stopped there. Reproduced on `main` (c62d5e3a) on Windows 11, Python 3.11.16: a temporary Strata folder with a read-only empty folder and a read-only file inside another folder, deleted through `Tools.strata_remove()`: ```text before: failed=["rt: [WinError 5] ...'\\mtp\\rt\\note.txt'", "tokenizer: [WinError 5] ...'\\packs\\iq2_xs\\tokenizer'"] folder_still_there=True after: failed=[] folder_still_there=False (both cases) ``` (The message text is in Chinese on this machine by its locale; the code is WinError 5, `ERROR_ACCESS_DENIED`.) ## Related discussion #4089 — the report, with the exact folders and the WinError 5 lines. A focused fix to an existing error hook, not a new feature, so no separate scope agreement was asked for. ## Approach - `_rmtree_ignore_missing()` still passes a path that is already gone (`FileNotFoundError`), so a folder a background scan emptied meanwhile keeps working. - On `PermissionError` it now clears the read-only attribute (`os.chmod(path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)`) and retries exactly that one path with the same function `shutil.rmtree` gave it (that is what pip's `rmtree_errorhandler` does for the same Windows rule). `func` is the operation that failed, so the retry is the same operation on the same path, not a deletion of the whole tree. - Any other `OSError`, and a retry that fails again, still count as a failure exactly as before: this does not hide a locked file (antivirus, a running process). - The permission bits `0o700` are the ones the hook needs on any platform; on Windows `os.chmod` maps them to the single read-only bit. ## Validation **Passed:** the new regression test on the branch, `python -m pytest tools/test_strata_mcp.py -q -k RemoveReadOnly` (Python 3.11.16, Windows 11): **1 passed, 52 deselected**. It builds a read-only empty folder, a read-only file in another folder, and the model's config, and asserts `strata_remove()` reports `failed: []` and that all three are gone. **Passed:** the module's full suite on the branch, `python -m pytest tools/test_strata_mcp.py -q`: **1 failed, 52 passed** — the one failure is `MacCatalog::test_deepseek_on_a_mac_offers_the_two_sets_that_were_run_with_the_mac_words`, which already fails on unmodified `main` in this checkout (it predates UD-IQ1_S/M being offered on a Mac) and is unrelated to this change. **Failed:** the same new test on unmodified `main` (only the hook reverted, the test kept): `AssertionError: Lists differ: ["rt: [WinError 5] ...", "tokenizer: [WinError 5] ..."] != []` at `tools/test_strata_mcp.py:998`. That is the A/B: the test pins the change. **Not run:** a real model delete from the desktop app on this machine (it needs a multi-GB installed pack), and this test's run on Linux/macOS (the read-only attribute is a Windows rule; the test skips there). ## Limits - Only `PermissionError` is retried. A denial from ACLs or a folder held open by another process still fails, as it should; the fix is specifically the Windows read-only attribute. - The change is cross-platform by construction but was only measured on Windows 11. On POSIX the condition is rare (unlink/rmdir rights come from the parent), so the POSIX branch is untested here. - The retry clears the attribute on the one path being removed. Files inside a read-only folder are handled one by one as `shutil.rmtree` descends, which is what `func` gives the hook. --- <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 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
Niko1221/Strata#5242
No description provided.