@@ -413,11 +413,15 @@ fn handle_dir(path: &Path, options: &Options) -> bool {
413413 had_err = remove_dir ( path, options) . bitor ( had_err) ;
414414 } else if options. recursive {
415415 if is_root || !options. preserve_root {
416- show_error ! ( "it is dangerous to operate recursively on '/'" ) ;
416+ show_error ! (
417+ "it is dangerous to operate recursively on '{}'" ,
418+ MAIN_SEPARATOR
419+ ) ;
417420 show_error ! ( "use --no-preserve-root to override this failsafe" ) ;
421+ } else {
422+ show_error ! ( "could not remove directory {}" , path. quote( ) ) ;
423+ had_err = true ;
418424 }
419- show_error ! ( "could not remove directory {}" , path. quote( ) ) ;
420- had_err = true ;
421425 } else {
422426 show_error ! (
423427 "cannot remove {}: Is a directory" , // GNU's rm error message does not include help
@@ -623,7 +627,6 @@ fn handle_writable_directory(path: &Path, options: &Options, metadata: &Metadata
623627/// Removes trailing slashes, for example 'd/../////' yield 'd/../' required to fix rm-r4 GNU test
624628fn clean_trailing_slashes ( path : & Path ) -> & Path {
625629 let path_str = os_str_as_bytes ( path. as_os_str ( ) ) ;
626-
627630 let dir_separator = MAIN_SEPARATOR as u8 ;
628631
629632 if let Ok ( path_bytes) = path_str {
@@ -643,7 +646,13 @@ fn clean_trailing_slashes(path: &Path) -> &Path {
643646 break ;
644647 }
645648 }
649+ #[ cfg( unix) ]
646650 return Path :: new ( OsStr :: from_bytes ( & path_bytes[ 0 ..=idx] ) ) ;
651+
652+ #[ cfg( not( unix) ) ]
653+ // Unwrapping is fine here as os_str_as_bytes() would return an error on non unix
654+ // systems with non utf-8 characters and thus bypass the if let Ok branch
655+ return Path :: new ( std:: str:: from_utf8 ( & path_bytes[ 0 ..=idx] ) . unwrap ( ) ) ;
647656 }
648657 }
649658 path
0 commit comments