fix(libc): rename onto or from a Windows directory symbolic link like a link #9661
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9661"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T07:10:04Z.
What
On Windows,
renametreated a symbolic link to a directory (or a junction) as the directory it names. FreeBSD 11.4'skern_renameatlooks up the last component of both paths withoutFOLLOW, so a symbolic link is renamed or replaced as the link itself, whatever it points to. Measured onmaind6eafa54d0with a file, an empty directory and two links to a directory:main(Windows)rename(file, link to a directory)EISDIRrename(link to a directory, existing file)ENOTDIRrename(link to a directory, empty directory)EISDIRThe cause is
RenamePath_nid_no_patch: under MinGW,std::filesystem::symlink_statusreports a Windows directory symbolic link as a directory instead of a link.sourceIsDirectoryanddestinationIsDirectorynow also require that the path is not a symbolic link or a junction, recognised by the reparse tag (IO_REPARSE_TAG_SYMLINK,IO_REPARSE_TAG_MOUNT_POINT). Other reparse points, such as cloud placeholder folders, are still directories. Everything after that decision is unchanged, includingRenameNative_nid_no_patch, which already opens the source withFILE_FLAG_OPEN_REPARSE_POINT. Linux reports links as links and is unchanged.Tested
Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release,
-DBUILD_TESTING=ON, onmaind6eafa54d0, Developer Mode on so links can be created.guest_filesystem: new checks after the existingrenameones, with a directory, an empty directory, two directory links and two files: the three calls in the table give the FreeBSD results, the replaced file's contents and the linked directory's contents are checked, and the links are removed afterwards (withRemoveDirectoryWon Windows, sinceunlinkof a directory link is #7530's area). Without link permission those checks are skipped with a message. On Windows the same three calls also run on two junctions made withmklink /J(absolute target), which needs no Developer Mode, so they run on every Windows machine (suggested by @JJenkx, who checked junctions locally first). Onmainthe test fails at the first new check (rename(link to a directory, empty directory)returns 0), and with the symbolic-link cases skipped it fails at the first junction check; with this PR it passes, three runs out of three.file_streams,guest_kernel_rename,guest_rename_dot,guest_kernel_sync,guest_kernel_sys,guest_kqueue,guest_path_case,guest_path_name_length,guest_posix_scalar_io(the other tests that callrename): pass.maind6eafa54d0and onmainwith this PR merged together with #9442, #9469, #9474, #9487 and #9496, same machine: 1890 tests each, identical results (1869 passed, 18 skipped; on both, the 3agc_driver_sample_order*tests fail andagc_driver_image_array_window_past_layer_limitis not built, as its 64 KiBalignasis rejected by this MinGW toolchain).python tools/check_conventions.py --base upstream/main: passes.main; see the comment.std::filesystem::create_directory_symlink), a console, a title run.Overlaps
tools/pr_overlap.py --branchlists no direct overlap; a trial merge with #8696 (renamethrough a link loop, also inRename.cpp) is clean.sameFilecheck a few lines below the two changed lines inRenamePath_nid_no_patch, without changing the directory decision; whichever lands second may need a text-only rebase. #6044 movesGuestFilesystem.cpptotests/files/; if it lands first, the new cases move with the file. #7202, #7530 and #9095 do not changeRename.cpp.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryAI-assisted (Claude Code).
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-22T07:25:58Z.
Independent Windows check of db944e4cd8, on a second machine: Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, WinLibs GCC 15.2.0 r7 (UCRT), Ninja, Release,
-DBUILD_TESTING=ON, Developer Mode on.maind6eafa54d0with only this PR'sGuestFilesystem.cpp:guest_filesystemaborts in the new block, before any later check runs.guest_filesystem,file_streams,guest_kernel_rename,guest_rename_dot,guest_kernel_sync,guest_kernel_sys,guest_kqueue,guest_path_case,guest_path_name_lengthandguest_posix_scalar_iopass in three runs out of three. The link cases ran each time; the "symbolic links unavailable" message never appeared.IO_REPARSE_TAG_MOUNT_POINTbut the test doesn't create: I made a local, uncommitted copy of the new block that makes both links withmklink /J(absolute target) instead ofCreateSymbolicLinkWand requires that both are created. It passes three times out of three with this PR and fails onmain'sRename.cpp. So the three calls in the table give the same results for junctions as for directory symbolic links. If you want that covered, a junction variant of the block would be a small addition. Junctions need no Developer Mode, so it would also run on machines where the symbolic-link cases are skipped.Not tested: Linux, a console, a title run.
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T07:52:57Z.
Thanks @JJenkx for the second-machine run and the junction check. Added in 2b62d4d019: on Windows the same three calls now also run on two junctions made with
mklink /J(absolute target), outside the symbolic-link branch, so they run without Developer Mode. With this PRguest_filesystempasses three runs out of three; withmain'sRename.cppand the symbolic-link cases skipped it fails at the first junction check.check_conventions.pypasses, and the description now credits your run.Imported from boykopovar/AnyPS5. Originally posted by fogydes on 2026-10-22T08:13:00Z.
Reviewed; the semantic change itself is right for every reachable case: file → link-to-dir becomes a link-over-file rename instead of
EISDIR, link-to-dir → plain file replaces the file, link-to-dir → empty dir keeps guestEISDIR(21) as the test asserts, dir → link-to-dir still answersENOTDIRper POSIX/Linux, and dangling links stay non-dir viasymlink_status. The native rename opens withFILE_FLAG_OPEN_REPARSE_POINTso it moves or replaces the link itself, other reparse tags (OneDrive placeholders etc.) stay untouched because onlyIO_REPARSE_TAG_SYMLINK/MOUNT_POINTmatch, and Linux is outside the#iffork. Test rows and cleanup look right.One nit: in the success path, after
unlink_nid_postfix(directoryLink)succeeds, the Windows cleanup still callsRemoveDirectoryWondirectoryLinkandmovingLink, which are both gone or no longer directories at that point; the calls are silently ignored no-ops but could go.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T09:10:03Z.
Review: DISMISSED
The Windows-only reparse-tag check is narrowly scoped to symbolic links and mount-point junctions, and leaves other reparse directories intact. The reported table and added file/directory-link cases cover the relevant replacement directions; the second-machine junction run adds useful coverage. Exact-head diff-check and conventions pass; hosted conventions/eligibility/labels/report plus relinker Linux/Windows/macOS and ASan jobs pass. Separately, the test cleanup nit noted in the thread remains: after the link/file replacement assertions, the later
RemoveDirectoryWcalls formovingLinkanddirectoryLinktarget paths already moved or removed; they are harmless no-ops and can be dropped.I’ve noticed that holding this PR because of #5239 isn’t necessary. It’s fine for PRs to keep coming in; they’ll be handled in due course. Please disregard my earlier request to hold or defer it.
Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:41:06Z.
Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current
main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:43:56Z.
Thanks @fogydes and @MarcZX10. The cleanup is fixed in 528fa6ab44: on success only the link now named
rename-occupied.txtis removed, inside that branch, and the links and files a skipped run may leave are removed in the skipped branch, so no call targets a path that is already gone. Rebased ontomain8b3a6ba88;guest_filesystempasses andcheck_conventions.pypasses. The PR stays a draft under #5239 as noted above.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T12:39:46Z.
Review: COMMENTED
The latest head fixes the stale-path cleanup nit: success and skipped-link paths now remove only entries that still exist. I fetched the current PR head
528fa6aband independently rerangit diff --check upstream/main...HEADandpython3 tools/check_conventions.py --base upstream/main --head HEAD; both pass. Hosted conventions, eligibility, labels/report, relinker Linux/macOS/Windows matrix, ASan, register-context and write-watch checks also pass on this head.The PR's junction and Windows rename behavior remains supported by the author and independent Windows runs; the current hosted Windows product job is skipped, and I did not rerun that Windows-only test locally. I found no new code issue in the latest diff. The PR remains draft per your stated hold, so this is a review update rather than a readiness recommendation.