test(libkernel_sys): remove created symlinks before cleaning up on Windows #17894

Merged
JJenkx merged 1 commit from upstream-pr/17894 into main 2026-11-12 06:24:26 +00:00
JJenkx commented 2026-11-09 21:01:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-09T21:01:55Z.


What

On Windows, guest_kernel_sys_paths_symlinkat and guest_kernel_sys_paths_symlinkat_patched time out (20 s) every time on main. symlinkat itself works. The hang is in the test's cleanup.

The test deletes the link target data and then calls std::filesystem::remove_all(root) while link still points at it. With MinGW's libstdc++, symlink_status follows the link, so a dangling symlink looks absent. It's never removed, and remove_all retries the same entry forever. Under gdb, CreateFileW is called on <root>\link more than 140,000 times in 60 s. A standalone program that only calls std::filesystem::remove_all(dir, ec) on a directory holding one dangling symlink never returns either, built with WinLibs GCC 15.2.0.

On Windows the test now deletes every reparse-point entry under its directory first, with DeleteFileW, or RemoveDirectoryW for directory links. It finds them through GetFileAttributesW, which doesn't follow links, and then calls remove_all as before. Other hosts are unchanged. Library code is unchanged.

Limitation: std::filesystem::recursive_directory_iterator would still descend into a directory symlink on MinGW, since is_symlink always reports false there. This test only creates file symlinks.

Found by a full Windows sweep of main 7259cce111 after #9161 merged; details on #9161.

Tested

Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release, head 47fcf68f61 on main f439f7f3a0, non-admin user with symlink creation available:

  • All 8 guest_kernel_sys_paths_* tests pass in 3 of 3 runs, none skipped: statfs, symlinkat, symlinkat_errors and futimesat, each with its _patched variant.
  • No anyps5-kernel-sys-paths-* directory is left behind afterwards.
  • On main, both symlinkat tests time out in a full sweep and when rerun alone.

Not run on Linux or macOS; the change is inside #ifdef _WIN32.

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:5231123120 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/17894). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-09T21:01:55Z. --- ### What On Windows, `guest_kernel_sys_paths_symlinkat` and `guest_kernel_sys_paths_symlinkat_patched` time out (20 s) every time on `main`. `symlinkat` itself works. The hang is in the test's cleanup. The test deletes the link target `data` and then calls `std::filesystem::remove_all(root)` while `link` still points at it. With MinGW's libstdc++, `symlink_status` follows the link, so a dangling symlink looks absent. It's never removed, and `remove_all` retries the same entry forever. Under gdb, `CreateFileW` is called on `<root>\link` more than 140,000 times in 60 s. A standalone program that only calls `std::filesystem::remove_all(dir, ec)` on a directory holding one dangling symlink never returns either, built with WinLibs GCC 15.2.0. On Windows the test now deletes every reparse-point entry under its directory first, with `DeleteFileW`, or `RemoveDirectoryW` for directory links. It finds them through `GetFileAttributesW`, which doesn't follow links, and then calls `remove_all` as before. Other hosts are unchanged. Library code is unchanged. Limitation: `std::filesystem::recursive_directory_iterator` would still descend into a directory symlink on MinGW, since `is_symlink` always reports false there. This test only creates file symlinks. Found by a full Windows sweep of `main` `7259cce111` after #9161 merged; details on #9161. ### Tested Windows 11 Enterprise 22621, WinLibs GCC 15.2 UCRT, Release, head `47fcf68f61` on `main` `f439f7f3a0`, non-admin user with symlink creation available: - All 8 `guest_kernel_sys_paths_*` tests pass in 3 of 3 runs, none skipped: `statfs`, `symlinkat`, `symlinkat_errors` and `futimesat`, each with its `_patched` variant. - No `anyps5-kernel-sys-paths-*` directory is left behind afterwards. - On `main`, both `symlinkat` tests time out in a full sweep and when rerun alone. Not run on Linux or macOS; the change is inside `#ifdef _WIN32`. ### Checklist - [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
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!17894
No description provided.