fix(libkernel): detect Windows reparse points in lstat #2898

Merged
MarcZX10 merged 3 commits from upstream-pr/2898 into main 2026-10-10 23:13:25 +00:00
MarcZX10 commented 2026-10-10 18:07:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T18:07:58Z.


What

Detect Windows filesystem reparse points with GetFileAttributesW before lstat falls through to _wstat64. This preserves the existing unsupported-link exception instead of reporting a symlink as its target. Extend guest_filesystem on Windows to check file, directory, and dangling symlinks, including the exact exception text, unchanged guest errno, and untouched FileStat output.

Fixes #2886.

Tested

  • Linux x86_64, GCC 12.2, Release: built guest_filesystem_tests; guest_filesystem passed once and 5 repeated runs. The Windows-only symlink assertions are not exercised on Linux.
  • The issue report documents Windows 11 / MinGW GCC 15.2 validation of this GetFileAttributesW approach: full library build and the expanded test passed 5/5, and the test failed 5/5 without the guard. This environment does not have a Windows host or MinGW cross-compiler.
  • python3 tools/check_conventions.py --base upstream/main and git diff --check passed.

Checklist

  • Based on current main; live searches found no open PR for this issue or lstat
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No third-party code added
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4813362796 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2898). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T18:07:58Z. --- ### What Detect Windows filesystem reparse points with `GetFileAttributesW` before `lstat` falls through to `_wstat64`. This preserves the existing unsupported-link exception instead of reporting a symlink as its target. Extend `guest_filesystem` on Windows to check file, directory, and dangling symlinks, including the exact exception text, unchanged guest errno, and untouched `FileStat` output. Fixes #2886. ### Tested - Linux x86_64, GCC 12.2, Release: built `guest_filesystem_tests`; `guest_filesystem` passed once and 5 repeated runs. The Windows-only symlink assertions are not exercised on Linux. - The issue report documents Windows 11 / MinGW GCC 15.2 validation of this `GetFileAttributesW` approach: full library build and the expanded test passed 5/5, and the test failed 5/5 without the guard. This environment does not have a Windows host or MinGW cross-compiler. - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. ### Checklist - [x] Based on current `main`; live searches found no open PR for this issue or `lstat` - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No third-party code added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
screamm commented 2026-10-10 20:03:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T20:03:23Z.


Windows validation of the current head cd60e955 merged onto main 43e1425b.

Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, BUILD_TESTING=ON, Developer Mode enabled, full build including the libs target.

The new test does not compile on Windows:

core/libs/tests/GuestFilesystem.cpp:232:72: error: cannot convert 'const char*' to 'LPCWSTR' {aka 'const wchar_t*'}

missingName is a std::string (line 187), so its c_str() is narrow. std::filesystem::path(missingName).c_str() compiles.

With that fixed, the test fails at line 366 (remove_nid_postfix(root), guest errno 66 ENOTEMPTY): target-directory created at line 225 is never removed. Adding std::filesystem::remove(targetDirectory) to the cleanup Require at line 243 fixes it.

With both changes applied locally:

  • guest_filesystem passes 5/5 (--repeat until-fail:5).
  • ctest -E "^agc_|video_out" passes 383/383.
  • With main's NativeStat.cpp and this test, guest_filesystem fails at line 249 (the file-link check), so the coverage detects the previous behaviour.

Validation run with Claude Code assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101641225 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2898#issuecomment-6101641225). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T20:03:23Z. --- Windows validation of the current head `cd60e955` merged onto `main` `43e1425b`. Windows 11 Pro 26220, WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `BUILD_TESTING=ON`, Developer Mode enabled, full build including the `libs` target. **The new test does not compile on Windows:** ``` core/libs/tests/GuestFilesystem.cpp:232:72: error: cannot convert 'const char*' to 'LPCWSTR' {aka 'const wchar_t*'} ``` `missingName` is a `std::string` (line 187), so its `c_str()` is narrow. `std::filesystem::path(missingName).c_str()` compiles. **With that fixed, the test fails at line 366 (`remove_nid_postfix(root)`, guest errno 66 `ENOTEMPTY`):** `target-directory` created at line 225 is never removed. Adding `std::filesystem::remove(targetDirectory)` to the cleanup `Require` at line 243 fixes it. With both changes applied locally: - `guest_filesystem` passes 5/5 (`--repeat until-fail:5`). - `ctest -E "^agc_|video_out"` passes 383/383. - With `main`'s `NativeStat.cpp` and this test, `guest_filesystem` fails at line 249 (the file-link check), so the coverage detects the previous behaviour. Validation run with Claude Code assistance.
MarcZX10 commented 2026-10-10 20:15:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-10T20:15:06Z.


Thanks for testing this on Windows and catching both fixture problems. I updated the test to keep the missing target as a std::filesystem::path for CreateSymbolicLinkW, while retaining its narrow name for the guest libc calls, and added targetDirectory to cleanup.

The updated branch is rebased onto current main. I rebuilt guest_filesystem_tests on Linux and ran guest_filesystem five times; all five passed. Your Windows 11 run validates the two fixes on the Windows toolchain. The separate macOS Intel write_watch_threads timeout remains visible in the existing CI run and is unrelated to this filesystem change; I’m investigating it separately.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101742102 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2898#issuecomment-6101742102). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-10T20:15:06Z. --- Thanks for testing this on Windows and catching both fixture problems. I updated the test to keep the missing target as a `std::filesystem::path` for `CreateSymbolicLinkW`, while retaining its narrow name for the guest libc calls, and added `targetDirectory` to cleanup. The updated branch is rebased onto current `main`. I rebuilt `guest_filesystem_tests` on Linux and ran `guest_filesystem` five times; all five passed. Your Windows 11 run validates the two fixes on the Windows toolchain. The separate macOS Intel `write_watch_threads` timeout remains visible in the existing CI run and is unrelated to this filesystem change; I’m investigating it separately.
screamm commented 2026-10-10 20:26:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-10T20:26:26Z.


Rerun on the updated head a22206bf merged onto main 56fb1b3b, same Windows 11 / WinLibs GCC 15.2.0 r7 / Release setup with Developer Mode: the test compiles unchanged, guest_filesystem passes 5/5 (--repeat until-fail:5) and ctest -E "^agc_|video_out" passes 388/388.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101838659 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2898#issuecomment-6101838659). Originally posted by [screamm](https://github.com/screamm) on 2026-10-10T20:26:26Z. --- Rerun on the updated head `a22206bf` merged onto `main` `56fb1b3b`, same Windows 11 / WinLibs GCC 15.2.0 r7 / Release setup with Developer Mode: the test compiles unchanged, `guest_filesystem` passes 5/5 (`--repeat until-fail:5`) and `ctest -E "^agc_|video_out"` passes 388/388.
adriadam10 commented 2026-10-10 23:13:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T23:13:23Z.


Checked the diff, the guest_filesystem test (passes in the scoped Linux build and ctest) and @screamm's Windows 11 / MinGW GCC 15.2 run on a22206bf (test compiles, passes 5/5, full ctest 388/388). The Windows-only assertions don't run on Linux; merging on that evidence. Note that any reparse point (junctions, cloud placeholders) now throws the same unsupported-link exception rather than being stat'ed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6103203466 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2898#issuecomment-6103203466). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T23:13:23Z. --- Checked the diff, the `guest_filesystem` test (passes in the scoped Linux build and ctest) and @screamm's Windows 11 / MinGW GCC 15.2 run on `a22206bf` (test compiles, passes 5/5, full ctest 388/388). The Windows-only assertions don't run on Linux; merging on that evidence. Note that any reparse point (junctions, cloud placeholders) now throws the same unsupported-link exception rather than being stat'ed.
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!2898
No description provided.