@@ -618,12 +618,11 @@ fn build_dir(
618618 #[ cfg( unix) ]
619619 {
620620 use crate :: Preserve ;
621- use std:: os:: unix:: fs:: PermissionsExt ;
622621
623622 // we need to allow trivial casts here because some systems like linux have u32 constants in
624623 // in libc while others don't.
625624 #[ allow( clippy:: unnecessary_cast) ]
626- let mut excluded_perms = if matches ! ( options. attributes. ownership, Preserve :: Yes { .. } ) {
625+ let excluded_perms = if matches ! ( options. attributes. ownership, Preserve :: Yes { .. } ) {
627626 libc:: S_IRWXG | libc:: S_IRWXO // exclude rwx for group and other
628627 } else if matches ! ( options. attributes. mode, Preserve :: Yes { .. } ) {
629628 libc:: S_IWGRP | libc:: S_IWOTH //exclude w for group and other
@@ -634,13 +633,16 @@ fn build_dir(
634633 let umask = if let ( Some ( from) , Preserve :: Yes { .. } ) =
635634 ( copy_attributes_from, options. attributes . mode )
636635 {
637- !fs:: symlink_metadata ( from) ?. permissions ( ) . mode ( )
636+ // temporary u+wx permission before true permission is set by
637+ // `dirs_needing_permissions`.
638+ !0o300
638639 } else {
639640 uucore:: mode:: get_umask ( )
640641 } ;
641642
642- excluded_perms |= umask;
643- let mode = !excluded_perms & 0o777 ; //use only the last three octet bits
643+ let mode = !( excluded_perms | umask) ;
644+ // use only the last three octet bits
645+ let mode = mode & 0o777 ;
644646 std:: os:: unix:: fs:: DirBuilderExt :: mode ( & mut builder, mode) ;
645647 }
646648
0 commit comments