Skip to content

Commit 3882f38

Browse files
shskwmtsylvestre
authored andcommitted
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 7698e29 commit 3882f38

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
@@ -431,6 +431,17 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool {
431431
}
432432
}
433433

434+
// Base case 1: this is a file or a symbolic link.
435+
//
436+
// The symbolic link case is important because it could be a link to
437+
// a directory and we don't want to recurse. In particular, this
438+
// avoids an infinite recursion in the case of a link to the current
439+
// directory, like `ln -s . link`.
440+
if !path.is_dir() || path.is_symlink() {
441+
return remove_file(path, options);
442+
}
443+
444+
// Base case 2: check if a path is one the same file system
434445
if let Err(additional_reason) = check_one_fs(path, options) {
435446
if !additional_reason.is_empty() {
436447
show_error!("{}", additional_reason);
@@ -442,17 +453,7 @@ fn remove_dir_recursive(path: &Path, options: &Options) -> bool {
442453
return true;
443454
}
444455

445-
// Base case 1: this is a file or a symbolic link.
446-
//
447-
// The symbolic link case is important because it could be a link to
448-
// a directory and we don't want to recurse. In particular, this
449-
// avoids an infinite recursion in the case of a link to the current
450-
// directory, like `ln -s . link`.
451-
if !path.is_dir() || path.is_symlink() {
452-
return remove_file(path, options);
453-
}
454-
455-
// Base case 2: this is a non-empty directory, but the user
456+
// Base case 3: this is a non-empty directory, but the user
456457
// doesn't want to descend into it.
457458
if options.interactive == InteractiveMode::Always
458459
&& !is_dir_empty(path)

0 commit comments

Comments
 (0)