File tree 1 file changed +18
-7
lines changed
1 file changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -1066,17 +1066,28 @@ impl File {
1066
1066
cfg_if:: cfg_if! {
1067
1067
// futimens requires macOS 10.13, and Android API level 19
1068
1068
if #[ cfg( any( target_os = "android" , target_os = "macos" ) ) ] {
1069
- fn ts_to_tv( ts: & libc:: timespec) -> libc:: timeval {
1070
- libc:: timeval { tv_sec: ts. tv_sec, tv_usec: ( ts. tv_nsec / 1000 ) as _ }
1071
- }
1072
1069
cvt( unsafe {
1073
1070
weak!( fn futimens( c_int, * const libc:: timespec) -> c_int) ;
1074
- futimens. get( )
1075
- . map( |futimens| futimens( self . as_raw_fd( ) , times. 0 . as_ptr( ) ) )
1076
- . unwrap_or_else( || {
1071
+ match futimens. get( ) {
1072
+ Some ( futimens) => futimens( self . as_raw_fd( ) , times. 0 . as_ptr( ) ) ,
1073
+ #[ cfg( target_os = "macos" ) ]
1074
+ None => {
1075
+ fn ts_to_tv( ts: & libc:: timespec) -> libc:: timeval {
1076
+ libc:: timeval {
1077
+ tv_sec: ts. tv_sec,
1078
+ tv_usec: ( ts. tv_nsec / 1000 ) as _
1079
+ }
1080
+ }
1077
1081
let timevals = [ ts_to_tv( & times. 0 [ 0 ] ) , ts_to_tv( & times. 0 [ 1 ] ) ] ;
1078
1082
libc:: futimes( self . as_raw_fd( ) , timevals. as_ptr( ) )
1079
- } )
1083
+ }
1084
+ // futimes requires even newer Android.
1085
+ #[ cfg( target_os = "android" ) ]
1086
+ None => return Err ( io:: const_io_error!(
1087
+ io:: ErrorKind :: Unsupported ,
1088
+ "setting file times requires Android API level >= 19" ,
1089
+ ) ) ,
1090
+ }
1080
1091
} ) ?;
1081
1092
} else {
1082
1093
cvt( unsafe { libc:: futimens( self . as_raw_fd( ) , times. 0 . as_ptr( ) ) } ) ?;
You can’t perform that action at this time.
0 commit comments