Skip to content

Commit 42a24fb

Browse files
committed
rm: Refactor order of filesystem check in remove_dir_recursive
- Reorder the call to `check_one_fs` within `remove_dir_recursive` for better structure and logical flow. - Update comment descriptions to match the new sequence of operations.
1 parent 818bf02 commit 42a24fb

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/uu/rm/src/rm.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,17 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool {
456456
}
457457
}
458458

459+
// Base case 1: this is a file or a symbolic link.
460+
//
461+
// The symbolic link case is important because it could be a link to
462+
// a directory and we don't want to recurse. In particular, this
463+
// avoids an infinite recursion in the case of a link to the current
464+
// directory, like `ln -s . link`.
465+
if !path.is_dir() || path.is_symlink() {
466+
return remove_file(path, options);
467+
}
468+
469+
// Base case 2: check if a path is one the same file system
459470
if let Err(additional_reason) = check_one_fs(path, options) {
460471
if !additional_reason.is_empty() {
461472
show_error!("{}", additional_reason);
@@ -467,17 +478,7 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool {
467478
return true;
468479
}
469480

470-
// Base case 1: this is a file or a symbolic link.
471-
//
472-
// The symbolic link case is important because it could be a link to
473-
// a directory and we don't want to recurse. In particular, this
474-
// avoids an infinite recursion in the case of a link to the current
475-
// directory, like `ln -s . link`.
476-
if !path.is_dir() || path.is_symlink() {
477-
return remove_file(path, options);
478-
}
479-
480-
// Base case 2: this is a non-empty directory, but the user
481+
// Base case 3: this is a non-empty directory, but the user
481482
// doesn't want to descend into it.
482483
if options.interactive == InteractiveMode::Always
483484
&& !is_dir_empty(path)

0 commit comments

Comments
 (0)