fix(libkernel): unlink a dangling Windows directory symbolic link #14197

Merged
JJenkx merged 1 commit from upstream-pr/14197 into main 2026-11-01 03:34:53 +00:00
JJenkx commented 2026-10-31 22:58:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-31T22:58:28Z.


What

On Windows, unlink on a directory symbolic link whose target is missing failed with EACCES (13), where FreeBSD removes the link.

sceKernelUnlink enters its Windows directory-link branch (FindFirstFileW → IO_REPARSE_TAG_SYMLINK → RemoveDirectoryW, added in b28edaf954) only when std::filesystem::is_directory(std::filesystem::symlink_status(native)) is true. With MinGW's libstdc++, symlink_status follows the link. A dangling directory link therefore reports "not found" rather than "directory", and the call falls through to the file delete. Windows removes a directory link only through RemoveDirectoryW, so that delete fails with access denied.

As a result, guest_filesystem aborts at line 1551 on main on any Windows host that may create symbolic links (Developer Mode or administrator):

Require(unlink_nid_postfix(directoryLink.string().c_str()) == 0 && unlink_nid_postfix(danglingDirectoryLink.string().c_str()) == 0);

Under gdb, the abort comes from Check for line 1551, with guest errno 13. On a host that cannot create links, the test skips this block, which is why hosted Windows CI does not see it.

unlink now also takes the directory-link branch when GetFileAttributesW reports both FILE_ATTRIBUTE_DIRECTORY and FILE_ATTRIBUTE_REPARSE_POINT on the path. That call describes the link itself, without following it. Inside the branch, FindFirstFileW finds the link entry whether or not its target exists, so RemoveDirectoryW removes the dangling link.

Linux and macOS are unchanged.

Tested

Windows 11 Enterprise 10.0.22621 (Developer Mode: unelevated symbolic link creation works), Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, full build with BUILD_TESTING=ON, on main 7a5d9bf02a.

  • guest_filesystem:
    • With this change: passes 3/3.
    • With Open.cpp restored to main (the control build relinked libkernel.prx): aborts again (0xc0000409).
    • It also failed in every earlier full-suite run on this machine.
  • ctest -R "file|fs|stat|dir|link|path|unlink|rename|kernel_sys" -j8 --repeat until-fail:3: 223/223 pass.
  • I found the failure in a host-only sweep of main 7a5d9bf02a (ctest -E ^agc, 2023 tests). It was one of two failures there; the other is ngs2_pitchshift, a separate known issue.
  • Not run: Linux and macOS (no change there), and no title.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5102333166 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14197). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-10-31T22:58:28Z. --- ### What On Windows, `unlink` on a directory symbolic link whose target is missing failed with `EACCES` (13), where FreeBSD removes the link. `sceKernelUnlink` enters its Windows directory-link branch (`FindFirstFileW` → `IO_REPARSE_TAG_SYMLINK` → `RemoveDirectoryW`, added in b28edaf954) only when `std::filesystem::is_directory(std::filesystem::symlink_status(native))` is true. With MinGW's libstdc++, `symlink_status` follows the link. A dangling directory link therefore reports "not found" rather than "directory", and the call falls through to the file delete. Windows removes a directory link only through `RemoveDirectoryW`, so that delete fails with access denied. As a result, `guest_filesystem` aborts at line 1551 on `main` on any Windows host that may create symbolic links (Developer Mode or administrator): ```cpp Require(unlink_nid_postfix(directoryLink.string().c_str()) == 0 && unlink_nid_postfix(danglingDirectoryLink.string().c_str()) == 0); ``` Under gdb, the abort comes from `Check` for line 1551, with guest errno 13. On a host that cannot create links, the test skips this block, which is why hosted Windows CI does not see it. `unlink` now also takes the directory-link branch when `GetFileAttributesW` reports both `FILE_ATTRIBUTE_DIRECTORY` and `FILE_ATTRIBUTE_REPARSE_POINT` on the path. That call describes the link itself, without following it. Inside the branch, `FindFirstFileW` finds the link entry whether or not its target exists, so `RemoveDirectoryW` removes the dangling link. Linux and macOS are unchanged. ### Tested Windows 11 Enterprise 10.0.22621 (Developer Mode: unelevated symbolic link creation works), Ryzen 9 5950X, WinLibs GCC 15.2.0 UCRT r7, Ninja, Release, full build with `BUILD_TESTING=ON`, on `main` `7a5d9bf02a`. - `guest_filesystem`: - With this change: passes 3/3. - With `Open.cpp` restored to `main` (the control build relinked `libkernel.prx`): aborts again (`0xc0000409`). - It also failed in every earlier full-suite run on this machine. - `ctest -R "file|fs|stat|dir|link|path|unlink|rename|kernel_sys" -j8 --repeat until-fail:3`: 223/223 pass. - I found the failure in a host-only sweep of `main` `7a5d9bf02a` (`ctest -E ^agc`, 2023 tests). It was one of two failures there; the other is `ngs2_pitchshift`, a separate known issue. - Not run: Linux and macOS (no change there), and no title. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
MarcZX10 commented 2026-10-31 23:14:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T23:14:48Z.

Review: APPROVED


Reviewed — looks good

The Windows path identifies a dangling directory symlink from its attributes and removes the link itself; the existing filesystem regression covers linked and dangling directory symlinks.

What I ran

Reviewed head b476f50b8e62718024ed5c1e5db1da5766330268 against PR base 7a5d9bf02af636382aec927593b1a5867899ed0f; the merge preview was clean. Reviewed on Linux x86_64, Python 3.11.2. The hosted Windows job ran on Windows Server 2025 with MinGW GCC 15.2.0. No local build or CTest was run.

python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14197 --output-dir /tmp/anyps5-pr-precheck-14197
gh pr checks 14197 --repo boykopovar/AnyPS5
gh run view 41250514758 --repo boykopovar/AnyPS5 --job 124684571029 --log

Results

Check Result
Diff check and repository conventions Passed
Dependency/merge preview Passed; clean
Hosted Windows job Passed
Hosted eligibility, intake, library portability, report Passed
Hosted labels Pending at review time
Linux and specialized hosted jobs Skipped by workflow
Local build and CTest Not run
ABI/test-quality helper checks Not executable: helper scripts are absent from the extracted PR head
Raw hosted status
windows	pass	2m46s	https://github.com/boykopovar/AnyPS5/actions/runs/41250514758/job/124684571029
intake	pass	5s	https://github.com/boykopovar/AnyPS5/actions/runs/41250514687/job/124682884489
library-portability	pass	1m42s	https://github.com/boykopovar/AnyPS5/actions/runs/41250514707/job/124682883651
report	pass	1m16s	https://github.com/boykopovar/AnyPS5/actions/runs/41250514713/job/124682883601
eligibility	pass	13s	https://github.com/boykopovar/AnyPS5/actions/runs/41250514758/job/124682883655

Negative control

No negative control was run; I did not alter the code or locally build the Windows-specific regression.

Sources

Not verified

  • No local build, CTest, Linux/macOS behavior, or console behavior.
  • The Windows test log completed successfully, but I did not confirm whether the symlink case was skipped for runner privilege reasons.

To get this to a good state

No blocking change is apparent from the code review and passing Windows job. The remaining labels check is administrative; no further code change is required for this review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5725401248 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/14197#pullrequestreview-5725401248). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-31T23:14:48Z. **Review:** APPROVED --- # Reviewed — looks good The Windows path identifies a dangling directory symlink from its attributes and removes the link itself; the existing filesystem regression covers linked and dangling directory symlinks. ## What I ran Reviewed head `b476f50b8e62718024ed5c1e5db1da5766330268` against PR base `7a5d9bf02af636382aec927593b1a5867899ed0f`; the merge preview was clean. Reviewed on Linux x86_64, Python 3.11.2. The hosted Windows job ran on Windows Server 2025 with MinGW GCC 15.2.0. No local build or CTest was run. ```sh python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 14197 --output-dir /tmp/anyps5-pr-precheck-14197 gh pr checks 14197 --repo boykopovar/AnyPS5 gh run view 41250514758 --repo boykopovar/AnyPS5 --job 124684571029 --log ``` ## Results | Check | Result | |---|---| | Diff check and repository conventions | Passed | | Dependency/merge preview | Passed; clean | | Hosted Windows job | Passed | | Hosted eligibility, intake, library portability, report | Passed | | Hosted labels | Pending at review time | | Linux and specialized hosted jobs | Skipped by workflow | | Local build and CTest | Not run | | ABI/test-quality helper checks | Not executable: helper scripts are absent from the extracted PR head | <details><summary>Raw hosted status</summary> ```text windows pass 2m46s https://github.com/boykopovar/AnyPS5/actions/runs/41250514758/job/124684571029 intake pass 5s https://github.com/boykopovar/AnyPS5/actions/runs/41250514687/job/124682884489 library-portability pass 1m42s https://github.com/boykopovar/AnyPS5/actions/runs/41250514707/job/124682883651 report pass 1m16s https://github.com/boykopovar/AnyPS5/actions/runs/41250514713/job/124682883601 eligibility pass 13s https://github.com/boykopovar/AnyPS5/actions/runs/41250514758/job/124682883655 ``` </details> ## Negative control No negative control was run; I did not alter the code or locally build the Windows-specific regression. ## Sources - [Windows symlink removal change at this PR head](https://github.com/boykopovar/AnyPS5/blob/b476f50b8e62718024ed5c1e5db1da5766330268/core/libs/prx/libc/src/Filesystem.cpp) - [Existing symlink regression coverage at this PR head](https://github.com/boykopovar/AnyPS5/blob/b476f50b8e62718024ed5c1e5db1da5766330268/core/libs/tests/GuestFilesystem.cpp) ## Not verified - No local build, CTest, Linux/macOS behavior, or console behavior. - The Windows test log completed successfully, but I did not confirm whether the symlink case was skipped for runner privilege reasons. ## To get this to a good state No blocking change is apparent from the code review and passing Windows job. The remaining labels check is administrative; no further code change is required for this review.
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!14197
No description provided.