@@ -298,9 +298,10 @@ pub(crate) fn finalize_entry(
298
298
/// See `let_readers_execute` for the exact details of how the mode is transformed.
299
299
#[ cfg( unix) ]
300
300
fn set_executable ( file : & std:: fs:: File ) -> Result < ( ) , std:: io:: Error > {
301
- let old_raw_mode = rustix:: fs:: fstat ( file) ?. st_mode ;
302
- let new_mode = let_readers_execute ( old_raw_mode) ;
303
- rustix:: fs:: fchmod ( file, new_mode) ?;
301
+ use std:: os:: unix:: fs:: { MetadataExt , PermissionsExt } ;
302
+ let old_mode = file. metadata ( ) ?. mode ( ) ;
303
+ let new_mode = let_readers_execute ( old_mode) ;
304
+ file. set_permissions ( std:: fs:: Permissions :: from_mode ( new_mode) ) ?;
304
305
Ok ( ( ) )
305
306
}
306
307
@@ -309,20 +310,16 @@ fn set_executable(file: &std::fs::File) -> Result<(), std::io::Error> {
309
310
/// Currently this adds executable bits for whoever has read bits already. It doesn't use the umask.
310
311
/// Set-user-ID and set-group-ID bits are unset for safety. The sticky bit is also unset.
311
312
///
312
- /// This returns only mode bits, not file type. The return value can be passed to chmod or fchmod.
313
- #[ cfg( unix) ]
314
- fn let_readers_execute ( mut raw_mode : rustix:: fs:: RawMode ) -> rustix:: fs:: Mode {
315
- assert_eq ! (
316
- raw_mode & 0o170000 ,
317
- 0o100000 ,
318
- "bug in caller if not from a regular file"
319
- ) ;
320
- raw_mode &= 0o777 ; // Clear type, non-rwx mode bits (setuid, setgid, sticky).
321
- raw_mode |= ( raw_mode & 0o444 ) >> 2 ; // Let readers also execute.
322
- rustix:: fs:: Mode :: from_bits ( raw_mode) . expect ( "all bits recognized" )
313
+ /// This returns only mode bits, not file type. The return value can be used in chmod or fchmod.
314
+ #[ cfg( any( unix, test) ) ]
315
+ fn let_readers_execute ( mut mode : u32 ) -> u32 {
316
+ assert_eq ! ( mode & 0o170000 , 0o100000 , "bug in caller if not from a regular file" ) ;
317
+ mode &= 0o777 ; // Clear type, non-rwx mode bits (setuid, setgid, sticky).
318
+ mode |= ( mode & 0o444 ) >> 2 ; // Let readers also execute.
319
+ mode
323
320
}
324
321
325
- #[ cfg( all ( test, unix ) ) ]
322
+ #[ cfg( test) ]
326
323
mod tests {
327
324
#[ test]
328
325
fn let_readers_execute ( ) {
@@ -372,8 +369,7 @@ mod tests {
372
369
( 0o106400 , 0o500 ) ,
373
370
( 0o102462 , 0o572 ) ,
374
371
] ;
375
- for ( st_mode, raw_expected) in cases {
376
- let expected = rustix:: fs:: Mode :: from_bits ( raw_expected) . expect ( "expected mode is a mode" ) ;
372
+ for ( st_mode, expected) in cases {
377
373
let actual = super :: let_readers_execute ( st_mode) ;
378
374
assert_eq ! (
379
375
actual, expected,
0 commit comments