Skip to content

rm: one-file-system#12819

Open
DarthStrom wants to merge 3 commits into
uutils:mainfrom
DarthStrom:rm-one-file-system
Open

rm: one-file-system#12819
DarthStrom wants to merge 3 commits into
uutils:mainfrom
DarthStrom:rm-one-file-system

Conversation

@DarthStrom

Copy link
Copy Markdown

Fixes #7011

Implements two related filesystem-boundary options for rm, previously parsed but ignored:

  • --one-file-system: while recursing, skip any directory on a different device than the tree root, printing skipping 'PATH', since it's on a different device and exiting non-zero (instead of failing with a raw "Device or resource busy").
  • --preserve-root=all: refuse to recurse across a device boundary (into a mount point), checked both for a directory named directly on the command line and for mounts reached during recursion.

The device check uses st_dev from fstatat/lstat and is Unix-only, matching the existing secure-traversal recursion; on other platforms the flags remain no-ops as before.

Testing

Added non-regression tests for the single-device case and for rejecting an unknown --preserve-root value. The authoritative cross-device behavior requires a mount point (root privileges), so it isn't exercised in CI; I verified it manually against the upstream GNU test suite, which now passes.

Previously --one-file-system was parsed but ignored, so a recursive
removal would descend into a mount point and fail with a raw
"Device or resource busy" error. Capture the device of the tree root
once and, while recursing on Unix, skip any directory whose device
differs from it, printing "skipping 'PATH', since it's on a different
device" and exiting non-zero.
GNU's --preserve-root=all refuses to recurse across a device boundary,
i.e. into a mount point. Accept the optional =all value and, on Unix,
skip any directory whose device differs from its parent's — both when
named directly on the command line and when reached during recursion —
printing the two-line diagnostic and exiting non-zero.

This complements --one-file-system, completing GNU-compatible handling
of mount points encountered during recursive removal.
@github-actions

github-actions Bot commented Jun 13, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

Skip an intermittent issue tests/misc/tty-eof (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tail/retry (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/timeout/timeout-group (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/rm/one-file-system is no longer failing!
Note: The gnu test tests/cp/link-heap is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Congrats! The gnu test tests/basenc/bounded-memory is now passing!

@codspeed-hq

codspeed-hq Bot commented Jun 13, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 4.11%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 322 untouched benchmarks
⏩ 46 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rm_single_file 47.1 ms 45.2 ms +4.11%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing DarthStrom:rm-one-file-system (3471175) with main (eee005a)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@sylvestre

Copy link
Copy Markdown
Contributor

excellent
i have been waiting for this test to be fixed for year, thanks :)

could you please fix the clippy warnings ?
thanks

clippy's unnecessary_cast fires on `st_dev as u64` on platforms where
libc::dev_t is already u64 (Linux), but the cast is required where it is
narrower (i32 on macOS). Compute the device once with the same
#[allow(clippy::unnecessary_cast)] the rest of the tree uses for st_dev,
which also removes the repeated cast at the comparison sites.
@DarthStrom

Copy link
Copy Markdown
Author

Sorry about that - apparently my clippy was a bit out-of-date. Hopefully this is an acceptable fix.

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.

rm --one-file-system should fail wih rm: skipping 'a/b', since it's on a different device

2 participants