Skip to content

file_system: a move onto an existing GAME: folder reports ERROR_ALREADY_EXISTS (FS-MOVE-ONTO-FOLDER) - #2375

Draft
syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/fs-move-onto-folder
Draft

syfyra wants to merge 1 commit into
ProjectLeonida:mainfrom
syfyra:fix/fs-move-onto-folder

Conversation

@syfyra

@syfyra syfyra commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: FS-MOVE-ONTO-FOLDER

What and why

MoveFileExW on console paths refused a move onto an existing folder with ERROR_ACCESS_DENIED, whatever the flags. The host only does that with MOVEFILE_REPLACE_EXISTING. Without it, any existing destination, a folder included, is "already there". Measured on Windows 11 with a small probe on an NTFS temp folder:

source → destination flags 0 or COPY_ALLOWED REPLACE_EXISTING (with or without COPY_ALLOWED)
file → empty folder 183 ERROR_ALREADY_EXISTS 5 ERROR_ACCESS_DENIED
file → non-empty folder 183 5
folder → folder (empty or not) 183 5
file → file 183 succeeds

A title that checks for ERROR_ALREADY_EXISTS to clear the way first and move again got ERROR_ACCESS_DENIED instead. MoveFileW, which passes no replace flag, has the same problem.

The shim now reports any existing destination as ERROR_ALREADY_EXISTS when MOVEFILE_REPLACE_EXISTING is not set, and a folder as ERROR_ACCESS_DENIED when it is. Nothing else changes. One case still differs from the host, as before this change: the host lets MOVEFILE_REPLACE_EXISTING move a folder over an existing file, and the shim keeps refusing that with ERROR_ACCESS_DENIED.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • file_system_test gets checks in its MoveFile block. A package file is moved onto a package folder (GAME:\data\sub) and onto an overlay folder (GAME:\cache\renamed) with MoveFileExW(0), MoveFileW and MoveFileExW(MOVEFILE_REPLACE_EXISTING), then an overlay folder onto a package folder. The checks confirm that the file and the folder stay where they were.
    • main: 5 of the new checks fail (each one that expects ERROR_ALREADY_EXISTS).
    • this branch: 546 of 546 pass.
  • Merges without new conflicts against the 18 open pull requests that change file_system.cpp or its test (checked with scripts/pr_overlap.py from scripts: pr_overlap.py lists the open pull requests that change the same files (PR-OVERLAP-CHECK) #2349). The six it lists as conflicting already conflict with main, and none of them touches these lines.
  • scripts/check_no_game_data.py on both files.

Not tested under Wine.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

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. (n/a: no translator change)

🤖 Generated with Claude Code

…DY_EXISTS (FS-MOVE-ONTO-FOLDER)

MoveFileEx onto a folder failed with ERROR_ACCESS_DENIED whatever the
flags. The host reports any existing destination, a folder too, as
ERROR_ALREADY_EXISTS without MOVEFILE_REPLACE_EXISTING, and
ERROR_ACCESS_DENIED only with it (measured on Windows 11 for a file and
a folder source, onto an empty and a non-empty folder). A title that
checks for ERROR_ALREADY_EXISTS to decide to clear the way first now
gets it. MoveFileW, which passes no replace flag, follows.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fiestorra

Copy link
Copy Markdown
Contributor

Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions.

1. It applies. merge-tree clean; the commits cherry-pick onto main d367675c7 without a conflict. Two files: runtime/shims/file_system.cpp and its test.

2. With the branch its test passes:

ctest -R 'file_system'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/file_system.cpp
cmake --build … --target file_system_test
ctest -R 'file_system' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL MoveFileExW of a file onto GAME:\data\sub reports ERROR_ALREADY_EXISTS
FAIL MoveFileW   of a file onto GAME:\data\sub reports ERROR_ALREADY_EXISTS

Both failures name the rule the change adds: moving a file onto an existing directory (GAME:\data\sub) must fail with ERROR_ALREADY_EXISTS, on both the ExW and the plain W entry point. main's shim lets one or both through.

One thing I noticed and did not judge: the assertion text uses GAME:\ as a root, which is the shim's own virtual root rather than a host path - so the check exercises the shim's path handling, not a real disk. That is consistent with the file being a shim test, and I have not checked that the error mapping matches what the console's file system actually returns for that case.

Why I am commenting: I verify open pull requests that replay onto current main, build the binaries their tests name in ctest --show-only=json-v1, run them, and then revert only the source change. 23 controls so far: 16 bite.

Written with an AI assistant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants