Skip to content

Commit 80693c1

Browse files
remove wrong if branch and modify a test
1 parent 733cca2 commit 80693c1

File tree

4 files changed

+29
-36
lines changed

4 files changed

+29
-36
lines changed

.cargo/config.toml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ linker = "x86_64-unknown-redox-gcc"
33

44
[target.'cfg(clippy)']
55
rustflags = [
6-
"-Wclippy::use_self",
7-
"-Wclippy::needless_pass_by_value",
8-
"-Wclippy::semicolon_if_nothing_returned",
9-
"-Wclippy::single_char_pattern",
10-
"-Wclippy::explicit_iter_loop",
11-
"-Wclippy::if_not_else",
6+
"-Wclippy::use_self",
7+
"-Wclippy::needless_pass_by_value",
8+
"-Wclippy::semicolon_if_nothing_returned",
9+
"-Wclippy::single_char_pattern",
10+
"-Wclippy::explicit_iter_loop",
11+
"-Wclippy::if_not_else",
1212
]
13-

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ thiserror = "1.0.59"
337337
time = { version = "0.3.36" }
338338
unicode-segmentation = "1.11.0"
339339
unicode-width = "0.1.12"
340+
utf-8 = "0.7.6"
340341
utmp-classic = "0.1.6"
341342
walkdir = "2.5"
342343
winapi-util = "0.1.8"

src/uu/rm/src/rm.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
336336
let path = clean_trailing_slashes(path);
337337
if path_is_current_or_parent_directory(path) {
338338
show_error!(
339-
"refusing to remove '.' or '..' directory: skipping '{:}'",
339+
"refusing to remove '.' or '..' directory: skipping '{}'",
340340
path.display()
341341
);
342342
return true;
@@ -412,17 +412,12 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
412412
} else if options.dir && (!is_root || !options.preserve_root) {
413413
had_err = remove_dir(path, options).bitor(had_err);
414414
} else if options.recursive {
415-
if is_root || !options.preserve_root {
416-
show_error!(
417-
"it is dangerous to operate recursively on '{}'",
418-
MAIN_SEPARATOR
419-
);
420-
show_error!("use --no-preserve-root to override this failsafe");
421-
had_err = true;
422-
} else {
423-
show_error!("could not remove directory {}", path.quote());
424-
had_err = true;
425-
}
415+
show_error!(
416+
"it is dangerous to operate recursively on '{}'",
417+
MAIN_SEPARATOR
418+
);
419+
show_error!("use --no-preserve-root to override this failsafe");
420+
had_err = true;
426421
} else {
427422
show_error!(
428423
"cannot remove {}: Is a directory", // GNU's rm error message does not include help
@@ -584,7 +579,7 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
584579
true
585580
}
586581
}
587-
/// Checks if the path is referring to current or parent directory , if it is referring to current or any parent directory in the file tree e.g '/.....' , '....' . '../..'
582+
/// Checks if the path is referring to current or parent directory , if it is referring to current or any parent directory in the file tree e.g '/../..' , '../..'
588583
fn path_is_current_or_parent_directory(path: &Path) -> bool {
589584
let path_str = os_str_as_bytes(path.as_os_str());
590585
let dir_separator = MAIN_SEPARATOR as u8;
@@ -684,3 +679,17 @@ fn is_symlink_dir(metadata: &Metadata) -> bool {
684679
metadata.file_type().is_symlink()
685680
&& ((metadata.file_attributes() & FILE_ATTRIBUTE_DIRECTORY) != 0)
686681
}
682+
683+
mod tests {
684+
685+
#[test]
686+
// Testing whether path the `/////` collapses to `/`
687+
fn test_collapsible_slash_path() {
688+
use std::path::Path;
689+
690+
use crate::clean_trailing_slashes;
691+
let path = Path::new("/////");
692+
693+
assert_eq!(Path::new("/"), clean_trailing_slashes(path));
694+
}
695+
}

tests/by-util/test_rm.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -319,22 +319,6 @@ fn test_rm_no_operand() {
319319
ts.ucmd().fails().usage_error("missing operand");
320320
}
321321

322-
#[test]
323-
#[cfg(not(windows))]
324-
// Windows doesn't have a root directory like unix
325-
fn test_rm_only_slashes_acting_as_root() {
326-
// We are testing the path '//////' which will be cleaned to be '/'.
327-
328-
let str_slashes = std::str::from_utf8(&[std::path::MAIN_SEPARATOR as u8; 6]).unwrap();
329-
330-
let ts = TestScenario::new(util_name!());
331-
ts.ucmd()
332-
.arg("-r")
333-
.arg(str_slashes)
334-
.fails()
335-
.stderr_contains("it is dangerous to operate recursively on");
336-
}
337-
338322
#[test]
339323
fn test_rm_verbose_slash() {
340324
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)