Commit Graph
78 Commits
Author SHA1 Message Date
Karthik VinayanandDaniel Hofstetter cf3b6d45ae rm: report permission denied for unreadable subdirectories
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
2026-02-16 15:06:20 +01:00
Yuri AstrakhanandGitHub 05204864d6 refactor: inline format! args in a few places (#10730)
* refactor: inline format! args in a few places

* in one spot remove redundant mem alloc

* run clippy fix with mixed
2026-02-07 10:05:44 +01:00
Sylvestre LedruandGitHub 5e5968cdbc rm: fix --preserve-root detection for nested symlinks with trailing slash (#9706) 2026-02-05 03:59:12 -08:00
RustyJackandGitHub ddd0379523 rm: fix for -rf ./ and variants silently delete current directoryFix/rm fr (#9924) 2026-01-24 19:33:05 +01:00
2fb45c188e rm: fix error reporting for -r on Linux fixing #9011 (#10111)
* rm: fix error reporting for -r on Linux

* rm: add stricter assertion for error tracking test

---------

Co-authored-by: Alex Lyon <dev@arct.rs>
2026-01-19 22:39:25 +01:00
364a23539d Rm no abbreviation no preserve root (#10205)
---------

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2026-01-19 09:32:14 +01:00
Gonçalo GomesandSylvestre Ledru fc17efe7be rm: don't treat symlinks as write-protected
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.
2026-01-17 23:51:11 +01:00
Sylvestre Ledru 8bf15fe676 rm: add the --progress option like with cp & mv 2025-10-22 00:27:49 +02:00
Sylvestre LedruandDaniel Hofstetter 5551c6a7ec Fix the last rm tests + add tests 2025-10-06 13:58:00 +02:00
Sylvestre Ledru 1183529cd2 rm: port to use the safe io functions 2025-09-12 14:22:33 +02:00
Daniel Hofstetter e01c414f97 rm: remove duplicate test
and adapt remaining test for wasi
2025-08-18 13:40:10 +02:00
Sylvestre Ledru f15dac138e chmod/readlink/du: improve non-UTF-8 filename handling and code style 2025-08-14 10:52:24 +02:00
Sylvestre Ledru a0f1e34d10 rm: fix handling of non-UTF-8 filenames 2025-08-14 10:52:24 +02:00
Daniel Hofstetter f33244321a rm: use clap to handle --interactive args 2025-07-31 09:49:05 +02:00
Tomasz Guz 9d34b622dd rm: fix too long filename corner case 2025-07-03 23:00:12 +02:00
Daniel Hofstetter 3ffaa335df rm: use new_cmd! to simplify some tests 2025-06-06 16:53:55 +02:00
Daniel Hofstetter d503b7c7c7 rm: merge some imports in test file 2025-06-06 16:42:32 +02:00
Daniel Hofstetter 1dbd452c8f rm: use consistent naming for test functions 2025-06-06 16:40:16 +02:00
bitspillandGitHub d957e64999 Merge pull request #7492 from bitspill/rm
rm: skip prompt when stdin is not interactive; Fix #7326
2025-04-27 23:54:16 +02:00
Yuri Astrakhan 982805d3cd chore: manual inline formatting
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).
2025-04-08 00:23:21 -04:00
Sylvestre Ledru a0179ea239 uutests: adjust the tests to use them 2025-03-28 21:40:31 +01:00
Sylvestre Ledru 18cb7dcf9e Use the new function fails_with_code
Done with
```
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.no_stdout\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2)\n\1.no_stdout();/gs' *rs
$ sed -i -e "s|.fails()(.*).code_is(|.fails_with_code(|g" *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)[ \t]*\n[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\2);/gs' *rs
$ perl -0777 -i -pe 's/([ \t]+)\.fails\(\)(.*?)[ \t]+\.code_is\(([0-9]+)\);/\1.fails_with_code(\3)\2;/gs' *rs
...
```
2025-03-01 17:26:20 +01:00
Jeffrey Finkelstein 2b531b78ef rm: correct prompt for removing inaccessible dir
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.
2025-02-18 18:39:45 -05:00
Jeffrey Finkelstein 1606968bf2 rm: recursive implementation of -r option
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.
2025-02-17 11:18:24 -05:00
Sylvestre LedruandGitHub 91784d0bff Merge pull request #7306 from jfinkels/rm-add-tests-interactive
rm: add two passing tests for -i option
2025-02-17 08:44:51 +01:00