@@ -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 '/../.. ' , '../..'
588583fn 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+ }
0 commit comments