When rm -rf encounters a subdirectory without read permission,
handle_permission_denied attempts unlink_at on it. If that fails
with ENOTEMPTY, force mode was silently swallowing the error,
causing the parent removal to fail with a misleading
"Directory not empty" message instead.
Now always reports permission denied when we cannot open a
subdirectory and cannot remove it directly.
Fixes#10966
GNU rm does not check for write-protection on symbolic links; it
instead prompts to "remove symbolic link" regardless of the link's
permissions or its target's status.
This change:
- Ensures `prompt_file` checks for symlinks specifically using
`symlink_metadata`, avoiding the incorrect "write-protected" prompt.
- Refactors permission checks into `is_writable_metadata` to allow
using the already-fetched metadata, which also optimizes performance
by reducing redundant `stat` calls.
- Updates `prompt_file_permission_readonly` to operate on metadata directly.
Minor manual cleanup - inlined many format args. This makes the code a bit more readable, and helps spot a few inefficiencies and possible bugs. Note that `&foo` in a `format!` parameter results in a 6% extra performance cost, and does not get inlined by the compiler (yet).
Change the prompt when attempting to remove an inaccessible
directory. Before this commit, the prompt was
rm: remove write-protected directory 'dir'?
After this commit, the prompt is
rm: attempt removal of inaccessible directory 'dir'?
This required slightly adjusting the logic for which prompt messages to
display under which circumstances.
Fixes#7309.
Change the implementation of `rm -r` so that it is explicitly recursive
so that (1) there is one code path regardless of whether `--verbose` is
given and (2) it is easier to be compatible with GNU `rm`.
This change eliminates a dependency on the `walkdir` crate.
Fixes#7033, fixes#7305, fixes#7307.