Skip to content

Conversation

@ChrisDryden
Copy link
Collaborator

No description provided.

shskwmt and others added 10 commits December 6, 2025 19:36
This comment enhances the safety of recursive deletion in `rm` by introducing two key features to
prevent accidental data loss.

`--one-file-system`: When specified, `rm` will not traverse into directories that are on a
different file system from the one on which the traversal began, this prevents `rm -r` from
accidentally deleting data on mounted volumes.

`--preserve-root=all`: The `--preserve-root` option is enhanced to accept an optional argument,
`all`. When set to `all`, `rm` will refuse to remove any directory that is a mount point. The
default behavior (`--preserve-root` without an argument) remains, protecting only the root
directory (`/`).
- Replace `.unwrap()` with `.map()` to handle options safely without risking panics.
- Update the abbreviation check to compare against the `PreserveRoot` enum directly.
Replace empty error strings with descriptive messages when path parent
or mount point resolution fails. This aids in debugging by identifying
specifically which path caused the resolution failure during the
one-file-system check.
Introduce `check_and_report_one_fs` to encapsulate the logic for
verifying filesystem boundaries (`-x`) and root preservation.

This removes code duplication between `remove_dir_recursive` and
`handle_dir`, ensuring consistent error reporting for "different device"
skips and `--preserve-root=all` violations.
Split the initialization of `stat_path` in `Filesystem::new` into distinct
`#[cfg(unix)]` and `#[cfg(windows)]` blocks. This improves readability and
ensures that Windows builds consistently use the volume ID (`dev_id`).
@ChrisDryden ChrisDryden deleted the fix-stdbuf-gnu-test branch January 27, 2026 04:00
@oech3
Copy link
Contributor

oech3 commented Jan 27, 2026

What test?

@oech3
Copy link
Contributor

oech3 commented Jan 27, 2026

depending on #10352 to remove sudo? or LIBSTDBUF_DIR=/tmp?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants