Skip to content

Commit 198f365

Browse files
rm: use "traversal failed" message when readdir fails during recursive removal
When readdir fails mid-traversal (e.g., due to I/O errors), GNU rm reports "traversal failed: <dir>" rather than "cannot remove '<dir>'". Update the error handling in safe_remove_dir_recursive_impl to match this behavior. Fixes GNU test: tests/rm/rm-readdir-fail.sh Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 2ef0aea commit 198f365

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

tests/by-util/test_rm.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use std::process::Stdio;
99

1010
use uutests::{at_and_ucmd, new_ucmd, util::TestScenario, util_name};
11+
#[cfg(unix)]
12+
use rlimit::Resource;
1113

1214
#[test]
1315
fn test_invalid_arg() {
@@ -1377,3 +1379,23 @@ fn test_preserve_root_literal_root() {
13771379
.stderr_contains("it is dangerous to operate recursively on '/'")
13781380
.stderr_contains("use --no-preserve-root to override this failsafe");
13791381
}
1382+
1383+
/// Test that "traversal failed" message is shown when readdir fails during
1384+
/// recursive removal (e.g., due to file descriptor exhaustion).
1385+
#[cfg(unix)]
1386+
#[test]
1387+
fn test_traversal_failed_on_readdir_error() {
1388+
let (at, mut ucmd) = at_and_ucmd!();
1389+
at.mkdir_all("a/b");
1390+
at.touch("a/b/file");
1391+
1392+
// Use a very low file descriptor limit so that dup() inside readdir
1393+
// fails with EMFILE ("Too many open files"), triggering the
1394+
// "traversal failed" error path.
1395+
let result = ucmd
1396+
.args(&["-rf", "a"])
1397+
.limit(Resource::NOFILE, 5, 5)
1398+
.fails();
1399+
result.stderr_contains("traversal failed");
1400+
result.stderr_contains("Too many open files");
1401+
}

0 commit comments

Comments
 (0)