rm: remove directory symlinks via the directory-removal API on Windows - #14159
Open
Uarz wants to merge 1 commit into
Open
rm: remove directory symlinks via the directory-removal API on Windows#14159Uarz wants to merge 1 commit into
Uarz wants to merge 1 commit into
Conversation
In remove_dir_recursive, the symlink base case routed every symbolic link through remove_file (std::fs::remove_file / DeleteFileW). On Windows a symbolic link to a directory (a directory reparse point) cannot be deleted this way: DeleteFileW returns ERROR_ACCESS_DENIED, so 'rm -r' over a tree containing a directory symlink fails with 'cannot remove ...: Permission denied'. Route directory symlinks through remove_dir (std::fs::remove_dir / RemoveDirectoryW) via the existing is_symlink_dir helper, matching how the top-level remove() already handles them. Non-Windows behavior is unchanged; the new branch is #[cfg(windows)] and otherwise falls back to remove_file. Adds a regression test in tests/by-util/test_rm.rs.
sylvestre
reviewed
Aug 26, 2026
Comment on lines
+669
to
+675
| // | ||
| // On Windows, a symbolic link to a directory (a directory reparse | ||
| // point) cannot be removed with the file-deletion API used by | ||
| // `remove_file` -> it fails with `ERROR_ACCESS_DENIED`. Route such | ||
| // links through `remove_dir` (the directory-removal API), which | ||
| // removes the reparse point itself instead of following the link. | ||
| // This mirrors how the top-level `remove` already handles directory |
Contributor
There was a problem hiding this comment.
please make the comment shorter
|
GNU testsuite comparison: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
rm -rover a directory tree that contains a symbolic link to a directory fails on Windows withcannot remove ...: Permission denied.In
remove_dir_recursive, the symlink base case routes every symbolic link throughremove_file(std::fs::remove_file/DeleteFileW). On Windows a directory symlink (a directory reparse point) cannot be deleted that way —DeleteFileWreturnsERROR_ACCESS_DENIED. It needsRemoveDirectoryW(std::fs::remove_dir), which removes the reparse point itself instead of following the link.Route directory symlinks through
remove_dirvia the existingis_symlink_dirhelper, matching how the top-levelremovealready handles them. Non-Windows is unchanged (the new branch is#[cfg(windows)]and otherwise falls back toremove_file).Added a regression test in
tests/by-util/test_rm.rs. It needsSeCreateSymbolicLinkPrivilege, like the existingtest_symlink_dir, so it runs on Windows CI rather than privilege-less dev boxes.