@@ -84,6 +84,23 @@ pub trait ModuleWriterExt: ModuleWriter {
8484 Ok ( ( ) )
8585 }
8686
87+ fn add_file_infer_permissions (
88+ & mut self ,
89+ target : impl AsRef < Path > ,
90+ source : impl AsRef < Path > ,
91+ ) -> Result < ( ) > {
92+ let source = source. as_ref ( ) ;
93+
94+ #[ cfg( unix) ]
95+ let mode = source. metadata ( ) ?. permissions ( ) . mode ( ) ;
96+ #[ cfg( not( unix) ) ]
97+ let mode = 0o644 ;
98+
99+ let executable = ( 0o100 & mode) == 0o100 ;
100+
101+ self . add_file ( target, source, executable)
102+ }
103+
87104 /// Creates an empty file at the specified target
88105 fn add_empty_file ( & mut self , target : impl AsRef < Path > ) -> Result < ( ) > {
89106 self . add_data ( target, None , b"" . as_slice ( ) , false )
@@ -610,10 +627,6 @@ where
610627 }
611628}
612629
613- fn permission_is_executable ( mode : u32 ) -> bool {
614- ( 0o100 & mode) == 0o100
615- }
616-
617630#[ cfg( unix) ]
618631#[ inline]
619632fn default_permission ( executable : bool ) -> u32 {
@@ -1444,12 +1457,9 @@ pub fn write_python_part(
14441457 continue ;
14451458 }
14461459 }
1447- #[ cfg( unix) ]
1448- let mode = absolute. metadata ( ) ?. permissions ( ) . mode ( ) ;
1449- #[ cfg( not( unix) ) ]
1450- let mode = 0o644 ;
1460+
14511461 writer
1452- . add_file ( relative, & absolute, permission_is_executable ( mode ) )
1462+ . add_file_infer_permissions ( relative, & absolute)
14531463 . context ( format ! ( "File to add file from {}" , absolute. display( ) ) ) ?;
14541464 }
14551465 }
@@ -1471,11 +1481,7 @@ pub fn write_python_part(
14711481 {
14721482 let target = source. strip_prefix ( pyproject_dir) ?. to_path_buf ( ) ;
14731483 if !source. is_dir ( ) {
1474- #[ cfg( unix) ]
1475- let mode = source. metadata ( ) ?. permissions ( ) . mode ( ) ;
1476- #[ cfg( not( unix) ) ]
1477- let mode = 0o644 ;
1478- writer. add_file ( target, source, permission_is_executable ( mode) ) ?;
1484+ writer. add_file_infer_permissions ( target, source) ?;
14791485 }
14801486 }
14811487 }
@@ -1574,25 +1580,16 @@ pub fn add_data(
15741580 . build ( )
15751581 {
15761582 let file = file?;
1577- #[ cfg( unix) ]
1578- let mode = file. metadata ( ) ?. permissions ( ) . mode ( ) ;
1579- #[ cfg( not( unix) ) ]
1580- let mode = 0o644 ;
15811583 let relative = metadata24
15821584 . get_data_dir ( )
15831585 . join ( file. path ( ) . strip_prefix ( data) . unwrap ( ) ) ;
15841586
15851587 if file. path_is_symlink ( ) {
15861588 // Copy the actual file contents, not the link, so that you can create a
15871589 // data directory by joining different data sources
1588- let source = fs:: read_link ( file. path ( ) ) ?;
1589- writer. add_file (
1590- relative,
1591- source. parent ( ) . unwrap ( ) ,
1592- permission_is_executable ( mode) ,
1593- ) ?;
1590+ writer. add_file_infer_permissions ( relative, file. path ( ) ) ?;
15941591 } else if file. path ( ) . is_file ( ) {
1595- writer. add_file ( relative, file. path ( ) , permission_is_executable ( mode ) ) ?;
1592+ writer. add_file_infer_permissions ( relative, file. path ( ) ) ?;
15961593 } else if file. path ( ) . is_dir ( ) {
15971594 // Intentionally ignored
15981595 } else {
0 commit comments