@@ -724,14 +724,7 @@ impl StrictPath {
724
724
return Err ( e) ;
725
725
}
726
726
727
- if let Err ( e) = self . unset_readonly ( context) {
728
- log:: warn!( "[{context}] failed to unset read-only on source: {:?} | {e}" , & self ) ;
729
- return Err ( std:: io:: Error :: new (
730
- std:: io:: ErrorKind :: Other ,
731
- "Failed to unset read-only" ,
732
- ) ) ;
733
- }
734
- if let Err ( e) = target_file. unset_readonly ( context) {
727
+ if let Err ( e) = target_file. unset_readonly ( ) {
735
728
log:: warn!(
736
729
"[{context}] failed to unset read-only on target: {:?} | {e}" ,
737
730
& target_file
@@ -747,6 +740,18 @@ impl StrictPath {
747
740
return Err ( e) ;
748
741
}
749
742
743
+ // We do this again in case the source file was also read-only.
744
+ if let Err ( e) = target_file. unset_readonly ( ) {
745
+ log:: warn!(
746
+ "[{context}] failed to unset read-only on target after copy: {:?} | {e}" ,
747
+ & target_file
748
+ ) ;
749
+ return Err ( std:: io:: Error :: new (
750
+ std:: io:: ErrorKind :: Other ,
751
+ "Failed to unset read-only" ,
752
+ ) ) ;
753
+ }
754
+
750
755
let mtime = match self . get_mtime ( ) {
751
756
Ok ( x) => x,
752
757
Err ( e) => {
@@ -790,32 +795,29 @@ impl StrictPath {
790
795
}
791
796
}
792
797
793
- pub fn unset_readonly ( & self , context : & str ) -> Result < ( ) , AnyError > {
798
+ pub fn unset_readonly ( & self ) -> Result < ( ) , AnyError > {
799
+ if !self . is_file ( ) {
800
+ return Ok ( ( ) ) ;
801
+ }
802
+
794
803
let subject = self . as_std_path_buf ( ) ?;
795
- if self . is_file ( ) {
796
- let mut perms = std:: fs:: metadata ( & subject) ?. permissions ( ) ;
797
- if perms. readonly ( ) {
804
+ let mut perms = std:: fs:: metadata ( & subject) ?. permissions ( ) ;
805
+
806
+ if perms. readonly ( ) {
807
+ #[ cfg( windows) ]
808
+ {
798
809
#[ allow( clippy:: permissions_set_readonly_false) ]
799
810
perms. set_readonly ( false ) ;
800
- std:: fs:: set_permissions ( & subject, perms) ?;
801
811
}
802
- } else {
803
- for entry in walkdir:: WalkDir :: new ( subject)
804
- . max_depth ( 100 )
805
- . follow_links ( false )
806
- . into_iter ( )
807
- . skip ( 1 ) // the base path itself
808
- . filter_map ( |x| crate :: prelude:: filter_map_walkdir ( context, x) )
809
- . filter ( |x| x. file_type ( ) . is_file ( ) )
812
+
813
+ #[ cfg( unix) ]
810
814
{
811
- let file = entry. path ( ) . display ( ) . to_string ( ) ;
812
- let mut perms = std:: fs:: metadata ( & file) ?. permissions ( ) ;
813
- if perms. readonly ( ) {
814
- #[ allow( clippy:: permissions_set_readonly_false) ]
815
- perms. set_readonly ( false ) ;
816
- std:: fs:: set_permissions ( & file, perms) ?;
817
- }
815
+ use std:: os:: unix:: fs:: PermissionsExt ;
816
+
817
+ perms. set_mode ( perms. mode ( ) | 0b110_000_000 ) ;
818
818
}
819
+
820
+ std:: fs:: set_permissions ( & subject, perms) ?;
819
821
}
820
822
821
823
Ok ( ( ) )
0 commit comments