From de8cb53d5498ce914ba82bc02c6a3f39dc03f3bf Mon Sep 17 00:00:00 2001 From: Jan Trencansky Date: Tue, 24 Nov 2026 07:02:11 -0500 Subject: file_system: RemoveDirectory and a create inside the folder are ordered as on the host Restores old upstream PR 9215 in ItsNotRexed/Leonida (closed unmerged when that repository went private), ported onto the current main: 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. A GAME: write-open checked that its folder exists, mirrored it into the overlay and then opened the file, and RemoveDirectory checked that the folder was empty and wrote its marker, neither under a lock. A remove that ran between the open's check and its host CreateFile succeeded on an empty folder, and the open then made the folder and the file again: both calls succeeded and the removed folder was back. CreateDirectory of a folder inside it had the same gap. On Windows one of the two fails: the create with ERROR_PATH_NOT_FOUND or the remove with ERROR_DIR_NOT_EMPTY. A striped lock keyed by the folder's upper-cased name (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 from its check to the host call; RemoveDirectory holds the folder's from its view to the marker. Reads take no lock. file_system_test races the two calls on two threads, 2,000 rounds each for a creating CreateFileW (CREATE_NEW, CREATE_ALWAYS, OPEN_ALWAYS) and for CreateDirectoryW, and checks that they never both succeed, that the loser fails with the host's error and that a removed folder stays removed. Co-Authored-By: Claude Opus 5.5 --- docs/runtime_imports.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs') diff --git a/docs/runtime_imports.md b/docs/runtime_imports.md index 7b9f62d5a..7cad0eed7 100644 --- a/docs/runtime_imports.md +++ b/docs/runtime_imports.md @@ -232,7 +232,9 @@ and the `api-ms-win-core-file-*` sets a GDK title links against. package has, fails with `ERROR_ALREADY_EXISTS`; a missing parent with `ERROR_PATH_NOT_FOUND`. - `RemoveDirectory*` needs the folder empty in the title's view (`ERROR_DIR_NOT_EMPTY` otherwise). An overlay folder is removed; a package folder is hidden by a `.gta6rt-dir` marker inside its marker folder, and stays on disk. A marker - folder on its own (left by a file deleted below it) does not hide anything. + folder on its own (left by a file deleted below it) does not hide anything. A remove and a write-open or + `CreateDirectory*` inside the folder on another thread are ordered as on the host: one goes first, and the create + fails with `ERROR_PATH_NOT_FOUND` or the remove with `ERROR_DIR_NOT_EMPTY`, never both succeeding. - `MoveFile*` writes the destination in the overlay. A package file is copied there and its old name deleted by a marker; an overlay file or an overlay-only folder is renamed. An existing destination needs `MOVEFILE_REPLACE_EXISTING` even when only the package has it. Moving a package folder fails with -- cgit v1.2.3