@@ -23,7 +23,7 @@ use std::fs::Metadata;
2323use std:: os:: unix:: fs:: MetadataExt ;
2424
2525use std:: os:: unix:: ffi:: OsStrExt ;
26- use std:: path:: { Path , MAIN_SEPARATOR_STR } ;
26+ use std:: path:: { Path , MAIN_SEPARATOR } ;
2727
2828/// The various level of verbosity
2929#[ derive( PartialEq , Eq , Clone , Debug ) ]
@@ -214,23 +214,13 @@ fn is_root(path: &Path, would_traverse_symlink: bool) -> bool {
214214 // We cannot check path.is_dir() here, as this would resolve symlinks,
215215 // which we need to avoid here.
216216 // All directory-ish paths match "*/", except ".", "..", "*/.", and "*/..".
217- let looks_like_dir = match path. as_os_str ( ) . to_str ( ) {
218- // If it contains special character, prefer to err on the side of safety, i.e. forbidding the chown operation:
219- None => false ,
220- Some ( "." ) | Some ( ".." ) => true ,
221- Some ( path_str) => {
222- ( path_str. ends_with ( MAIN_SEPARATOR_STR ) )
223- || ( path_str. ends_with ( & format ! ( "{MAIN_SEPARATOR_STR}." ) ) )
224- || ( path_str. ends_with ( & format ! ( "{MAIN_SEPARATOR_STR}.." ) ) )
225- }
226- } ;
227- // TODO: Once we reach MSRV 1.74.0, replace this abomination by something simpler, e.g. this:
228- // let path_bytes = path.as_os_str().as_encoded_bytes();
229- // let looks_like_dir = path_bytes == [b'.']
230- // || path_bytes == [b'.', b'.']
231- // || path_bytes.ends_with(&[MAIN_SEPARATOR as u8])
232- // || path_bytes.ends_with(&[MAIN_SEPARATOR as u8, b'.'])
233- // || path_bytes.ends_with(&[MAIN_SEPARATOR as u8, b'.', b'.']);
217+ let path_bytes = path. as_os_str ( ) . as_encoded_bytes ( ) ;
218+ let looks_like_dir = path_bytes == [ b'.' ]
219+ || path_bytes == [ b'.' , b'.' ]
220+ || path_bytes. ends_with ( & [ MAIN_SEPARATOR as u8 ] )
221+ || path_bytes. ends_with ( & [ MAIN_SEPARATOR as u8 , b'.' ] )
222+ || path_bytes. ends_with ( & [ MAIN_SEPARATOR as u8 , b'.' , b'.' ] ) ;
223+
234224 if !looks_like_dir {
235225 return false ;
236226 }
0 commit comments