Skip to content

Commit 5fa7f6d

Browse files
rm: fix rustfmt, cspell, and clippy CI failures
- Run rustfmt to fix formatting in safe_remove_dir_recursive_impl - Replace British English spellings with American English in comments (materialising→materializing, minimising→minimizing, amortised→amortized, initialisation→initialization, behaviour→behavior) - Fix clippy: use inline format arg in panic! in safe_traversal test - Add technical terms to cspell jargon dictionary: EMFILE, ENFILE, ENOMEM, NOFILE, getdents, btrfs, diriter, readdir Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent e064d8a commit 5fa7f6d

4 files changed

Lines changed: 33 additions & 19 deletions

File tree

.vscode/cspell.dictionaries/jargon.wordlist.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ dequeue
3333
dev
3434
EINTR
3535
eintr
36+
EMFILE
37+
emfile
38+
ENFILE
39+
ENOMEM
40+
getdents
41+
btrfs
42+
diriter
43+
NOFILE
44+
readdir
3645
nextest
3746
SIGUSR
3847
nonprinting

src/uu/rm/src/platform/unix.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ fn is_emfile(e: &io::Error) -> bool {
362362
/// A frame starts as `Live` (fd open, lazy iteration via `DirIter`). When
363363
/// the process runs out of file descriptors — which limits tree depth to
364364
/// approximately `RLIMIT_NOFILE` (≈ 1 024) — `try_reclaim_fd` demotes the
365-
/// oldest live frame to `Drained` by materialising its remaining entries into
365+
/// oldest live frame to `Drained` by materializing its remaining entries into
366366
/// a `Vec` and closing the fd. Subsequent entry-yielding uses the vec; fd
367367
/// operations (stat, unlink, open-child) temporarily re-open the directory
368368
/// from `StackFrame::dir_path`.
@@ -419,7 +419,7 @@ struct StackFrame {
419419
/// Returns `true` if a frame was demoted; `false` if all non-top frames are
420420
/// already `Drained` (which means we are genuinely out of fds).
421421
///
422-
/// Materialising the oldest frame first minimises the chance of collecting a
422+
/// Materializing the oldest frame first minimizes the chance of collecting a
423423
/// large sibling list: for deep linear chains the bottom frames have already
424424
/// exhausted their children before a new level is pushed.
425425
///
@@ -562,7 +562,7 @@ pub(super) fn safe_remove_dir_recursive_impl(
562562
options: &Options,
563563
progress_bar: Option<&ProgressBar>,
564564
) -> bool {
565-
// Iterative, allocation-minimising implementation.
565+
// Iterative, allocation-minimizing implementation.
566566
//
567567
// Design goals (see https://github.com/uutils/coreutils/issues/11222):
568568
// • One shared `PathBuf` for the entire traversal instead of one `join()`
@@ -577,7 +577,7 @@ pub(super) fn safe_remove_dir_recursive_impl(
577577
//
578578
// Fd budget: each `Live` frame holds exactly one open fd. When the process
579579
// runs out of file descriptors (`EMFILE`/`ENFILE`), `try_reclaim_fd` demotes
580-
// the oldest live frame to `Drained` — its remaining entries are materialised
580+
// the oldest live frame to `Drained` — its remaining entries are materialized
581581
// into a `Vec<OsString>` and its fd is closed. Subsequent fd-requiring
582582
// operations on a `Drained` frame re-open the directory from `dir_path` on
583583
// demand. This allows traversal of trees of arbitrary depth at the cost of
@@ -681,7 +681,7 @@ pub(super) fn safe_remove_dir_recursive_impl(
681681

682682
// ── Normal child entry ────────────────────────────────────────────
683683
Some(Ok(entry)) => {
684-
// Extend the shared path accumulator in-place — amortised O(1),
684+
// Extend the shared path accumulator in-place — amortized O(1),
685685
// no heap allocation if there is spare capacity.
686686
current_path.push(&entry.name);
687687

@@ -696,19 +696,18 @@ pub(super) fn safe_remove_dir_recursive_impl(
696696
//
697697
// Fallback: stat when in interactive mode (need mode/size for
698698
// the prompt) or when the filesystem reports DT_UNKNOWN.
699-
let needs_stat = options.interactive != InteractiveMode::Never
700-
|| entry.file_type.is_none();
699+
let needs_stat =
700+
options.interactive != InteractiveMode::Never || entry.file_type.is_none();
701701

702702
let (is_dir, stat_opt) = if needs_stat {
703703
match frame_stat_at(stack.last().unwrap(), entry.name.as_ref()) {
704704
Ok(s) => {
705-
let is_dir = ((s.st_mode as libc::mode_t) & libc::S_IFMT)
706-
== libc::S_IFDIR;
705+
let is_dir =
706+
((s.st_mode as libc::mode_t) & libc::S_IFMT) == libc::S_IFDIR;
707707
(is_dir, Some(s))
708708
}
709709
Err(e) => {
710-
let err =
711-
handle_error_with_force(e, current_path.as_path(), options);
710+
let err = handle_error_with_force(e, current_path.as_path(), options);
712711
stack.last_mut().unwrap().had_error |= err;
713712
current_path.pop();
714713
continue;
@@ -832,9 +831,7 @@ pub(super) fn safe_remove_dir_recursive_impl(
832831
// File or symlink: prompt then unlink.
833832
// In Never mode stat_opt is None and we always remove.
834833
let should_remove = match stat_opt {
835-
Some(ref s) => {
836-
prompt_file_with_stat(current_path.as_path(), s, options)
837-
}
834+
Some(ref s) => prompt_file_with_stat(current_path.as_path(), s, options),
838835
None => true,
839836
};
840837
if should_remove {

src/uucore/src/lib/features/safe_traversal.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,11 @@ mod tests {
14711471
fs::write(temp_dir.path().join("gamma"), "c").unwrap();
14721472

14731473
let dir_fd = DirFd::open(temp_dir.path(), SymlinkBehavior::Follow).unwrap();
1474-
let mut names: Vec<OsString> = dir_fd.iter_dir().unwrap().map(|r| r.unwrap().name).collect();
1474+
let mut names: Vec<OsString> = dir_fd
1475+
.iter_dir()
1476+
.unwrap()
1477+
.map(|r| r.unwrap().name)
1478+
.collect();
14751479
names.sort();
14761480

14771481
assert_eq!(
@@ -1498,7 +1502,11 @@ mod tests {
14981502
fs::write(temp_dir.path().join("file"), "x").unwrap();
14991503

15001504
let dir_fd = DirFd::open(temp_dir.path(), SymlinkBehavior::Follow).unwrap();
1501-
let names: Vec<OsString> = dir_fd.iter_dir().unwrap().map(|r| r.unwrap().name).collect();
1505+
let names: Vec<OsString> = dir_fd
1506+
.iter_dir()
1507+
.unwrap()
1508+
.map(|r| r.unwrap().name)
1509+
.collect();
15021510

15031511
assert!(!names.contains(&OsString::from(".")));
15041512
assert!(!names.contains(&OsString::from("..")));
@@ -1533,7 +1541,7 @@ mod tests {
15331541
// A sentinel file ensures the directory is non-empty, so the first
15341542
// `getdents64` call is deferred until after we close the fd below.
15351543
// Without it, an empty directory may return EOF (0) during Dir::from_fd
1536-
// initialisation, making iter.next() return None instead of Some(Err(_)).
1544+
// initialization, making iter.next() return None instead of Some(Err(_)).
15371545
fs::write(temp_dir.path().join("sentinel"), "x").unwrap();
15381546

15391547
let dir_fd = DirFd::open(temp_dir.path(), SymlinkBehavior::Follow).unwrap();
@@ -1555,7 +1563,7 @@ mod tests {
15551563
// the destructor would attempt on the already-closed fd.
15561564
match iter.next() {
15571565
Some(Err(_)) => {} // expected: EBADF propagated as io::Error
1558-
other => panic!("expected Some(Err(_)) after fd close, got {:?}", other),
1566+
other => panic!("expected Some(Err(_)) after fd close, got {other:?}"),
15591567
}
15601568
}
15611569
}

tests/by-util/test_rm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ fn test_recursive_interactive() {
10121012

10131013
// When the user declines to remove a subdirectory in interactive mode, rm
10141014
// should NOT report an error. The parent directory is left behind (because it
1015-
// is non-empty), but the process should exit 0 — matching GNU rm behaviour.
1015+
// is non-empty), but the process should exit 0 — matching GNU rm behavior.
10161016
#[cfg(not(windows))]
10171017
#[test]
10181018
fn test_recursive_interactive_decline_child_no_error() {

0 commit comments

Comments
 (0)