[PR #688] [MERGED] OLD-9215: restore old upstream PR 9215 - file_system: RemoveDirectory and a create inside the folder are ordered as on the host #728

Closed
opened 2026-11-26 20:18:51 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/688
Author: @aslan2142
Created: 11/24/2026
Status: ✅ Merged
Merged: 11/26/2026
Merged by: @aslan2142

Base: main ← Head: game-rmdir-create-race


📝 Commits (1)

  • de8cb53 file_system: RemoveDirectory and a create inside the folder are ordered as on the host

📊 Changes

3 files changed (+113 additions, -1 deletions)

View changed files

📝 docs/runtime_imports.md (+3 -1)
📝 runtime/shims/file_system.cpp (+40 -0)
📝 runtime/test/file_system_test.cpp (+70 -0)

📄 Description

Claimed in the coordination issue as: OLD-9215 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7130909581

Restoration of my original pull request, old upstream PR 9215 in ItsNotRexed/Leonida, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at 21625bca8; the write-open keeps main's long-path disk_path() for its overlay path, and the new race test sits after main's tests that recreate a removed package folder. Nothing else changed from the original.

What and why

  • The bug: a GAME: write-open or CreateDirectory* inside a folder could run its "does the folder exist" check, and then a RemoveDirectory* of that folder on another thread could run its emptiness check and write its marker. No lock covered either step.
    • Both calls then succeeded, and the removed folder came back with the new entry in it.
    • On Windows one of the two fails: the create with ERROR_PATH_NOT_FOUND, or the remove with ERROR_DIR_NOT_EMPTY.
  • The fix: a striped lock keyed by the folder's upper-cased name, made of 64 namespace-scope std::mutex (no function-local static).
    • write_target holds the lock of the folder it opens in, from the parent check until the Target is gone after the host CreateFile/CreateFile2.
    • CreateDirectory* holds the parent's lock from its check to the host call, which includes main's marker clean-up.
    • RemoveDirectory* holds the folder's lock from its view to the marker.
    • Reads take no lock.
  • The test: file_system_test races the two calls on two threads, 2,000 rounds for a creating CreateFileW (CREATE_NEW, CREATE_ALWAYS, OPEN_ALWAYS) and 2,000 for CreateDirectoryW. It checks three things: the two never both succeed, the loser fails with the host's error, and a removed folder stays removed.
  • Docs: docs/runtime_imports.md describes the ordering.
  • Not covered here: CreateDirectory of a removed package folder X racing RemoveDirectory of X itself. Main's CreateDirectory deletes X's removal marker after it makes the overlay folder, and a remove in between leaves X visible again although both calls succeeded.
    • A 2,000-round stress loop (not part of this PR) left X present in 1,993 rounds on main and 1,956 on this branch.
    • The locks here don't cover it, because the remove locks X and the create locks X's parent.
    • I'm reporting it separately in the coordination issue.

Tested

Linux, Wine 11.22 (Staging), file_system_test built with clang 23 for x86_64-w64-mingw32. MSVC /W4 /permissive- is left to CI.

  • main at 21625bca8: 494 checks, 11 failures.
    • All 11 are Wine-only: MAXIMUM_ALLOWED opens, long paths, and the host ReadFile ERROR_NOACCESS probe.
  • This pull request's test on main's shim: 500 checks, 15 failures. The 11 above, plus the 4 new race checks.
    • Creating CreateFileW: both calls succeeded in 1,972 of 2,000 rounds.
    • CreateDirectoryW: both calls succeeded in 1,012 of 2,000 rounds.
  • This branch: 500 checks, the same 11 failures.
    • Creating CreateFileW: create first 1,964, remove first 36, both 0.
    • CreateDirectoryW: remove first 2,000, both 0.
  • This branch merged with #684: merges cleanly, 525 checks, the same 11 failures, and both races at 0.
  • Also checked: git diff --check is clean, and python -I scripts/check_no_game_data.py passes on the three changed files.
  • git merge-tree shows no conflict with the other open pull requests that touch file_system.cpp: #684, #400, #317, #287, #271 and #115.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

AI-assisted (Claude Code, Claude Opus 5.5).


🔄 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/688 **Author:** [@aslan2142](https://github.com/aslan2142) **Created:** 11/24/2026 **Status:** ✅ Merged **Merged:** 11/26/2026 **Merged by:** [@aslan2142](https://github.com/aslan2142) **Base:** `main` ← **Head:** `game-rmdir-create-race` --- ### 📝 Commits (1) - [`de8cb53`](https://github.com/ubiquitarianism/leonida/commit/de8cb53d5498ce914ba82bc02c6a3f39dc03f3bf) file_system: RemoveDirectory and a create inside the folder are ordered as on the host ### 📊 Changes **3 files changed** (+113 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `docs/runtime_imports.md` (+3 -1) 📝 `runtime/shims/file_system.cpp` (+40 -0) 📝 `runtime/test/file_system_test.cpp` (+70 -0) </details> ### 📄 Description Claimed in the coordination issue as: OLD-9215 https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7130909581 Restoration of my original pull request, old upstream PR 9215 in `ItsNotRexed/Leonida`, which was closed unmerged when that repository went private on 2026-11-23 (old numbers link nowhere now). Ported onto main at 21625bca8; the write-open keeps main's long-path `disk_path()` for its overlay path, and the new race test sits after main's tests that recreate a removed package folder. Nothing else changed from the original. ### What and why - **The bug:** a `GAME:` write-open or `CreateDirectory*` inside a folder could run its "does the folder exist" check, and then a `RemoveDirectory*` of that folder on another thread could run its emptiness check and write its marker. No lock covered either step. - Both calls then succeeded, and the removed folder came back with the new entry in it. - On Windows one of the two fails: the create with `ERROR_PATH_NOT_FOUND`, or the remove with `ERROR_DIR_NOT_EMPTY`. - **The fix:** a striped lock keyed by the folder's upper-cased name, made of 64 namespace-scope `std::mutex` (no function-local static). - `write_target` holds the lock of the folder it opens in, from the parent check until the `Target` is gone after the host `CreateFile`/`CreateFile2`. - `CreateDirectory*` holds the parent's lock from its check to the host call, which includes main's marker clean-up. - `RemoveDirectory*` holds the folder's lock from its view to the marker. - Reads take no lock. - **The test:** `file_system_test` races the two calls on two threads, 2,000 rounds for a creating `CreateFileW` (`CREATE_NEW`, `CREATE_ALWAYS`, `OPEN_ALWAYS`) and 2,000 for `CreateDirectoryW`. It checks three things: the two never both succeed, the loser fails with the host's error, and a removed folder stays removed. - **Docs:** `docs/runtime_imports.md` describes the ordering. - **Not covered here:** `CreateDirectory` of a removed package folder X racing `RemoveDirectory` of X itself. Main's `CreateDirectory` deletes X's removal marker after it makes the overlay folder, and a remove in between leaves X visible again although both calls succeeded. - A 2,000-round stress loop (not part of this PR) left X present in 1,993 rounds on main and 1,956 on this branch. - The locks here don't cover it, because the remove locks X and the create locks X's parent. - I'm reporting it separately in the coordination issue. ### Tested Linux, Wine 11.22 (Staging), `file_system_test` built with clang 23 for `x86_64-w64-mingw32`. MSVC `/W4 /permissive-` is left to CI. - **main at 21625bca8:** 494 checks, 11 failures. - All 11 are Wine-only: `MAXIMUM_ALLOWED` opens, long paths, and the host `ReadFile` `ERROR_NOACCESS` probe. - **This pull request's test on main's shim:** 500 checks, 15 failures. The 11 above, plus the 4 new race checks. - Creating `CreateFileW`: both calls succeeded in 1,972 of 2,000 rounds. - `CreateDirectoryW`: both calls succeeded in 1,012 of 2,000 rounds. - **This branch:** 500 checks, the same 11 failures. - Creating `CreateFileW`: create first 1,964, remove first 36, both 0. - `CreateDirectoryW`: remove first 2,000, both 0. - **This branch merged with #684:** merges cleanly, 525 checks, the same 11 failures, and both races at 0. - Also checked: `git diff --check` is clean, and `python -I scripts/check_no_game_data.py` passes on the three changed files. - `git merge-tree` shows no conflict with the other open pull requests that touch `file_system.cpp`: #684, #400, #317, #287, #271 and #115. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. AI-assisted (Claude Code, Claude Opus 5.5). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:18:51 +01:00
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#728
No description provided.