@@ -1195,57 +1195,6 @@ impl fmt::Debug for OpenOptions {
1195
1195
}
1196
1196
}
1197
1197
1198
- #[ cfg( not( any(
1199
- target_os = "redox" ,
1200
- target_os = "espidf" ,
1201
- target_os = "horizon" ,
1202
- target_os = "nuttx" ,
1203
- ) ) ) ]
1204
- #[ inline( always) ]
1205
- fn to_timespec ( time : Option < SystemTime > ) -> io:: Result < libc:: timespec > {
1206
- match time {
1207
- Some ( time) if let Some ( ts) = time. t . to_timespec ( ) => Ok ( ts) ,
1208
- Some ( time) if time > crate :: sys:: time:: UNIX_EPOCH => Err ( io:: const_error!(
1209
- io:: ErrorKind :: InvalidInput ,
1210
- "timestamp is too large to set as a file time" ,
1211
- ) ) ,
1212
- Some ( _) => Err ( io:: const_error!(
1213
- io:: ErrorKind :: InvalidInput ,
1214
- "timestamp is too small to set as a file time" ,
1215
- ) ) ,
1216
- None => Ok ( libc:: timespec { tv_sec : 0 , tv_nsec : libc:: UTIME_OMIT as _ } ) ,
1217
- }
1218
- }
1219
-
1220
- #[ cfg( target_vendor = "apple" ) ]
1221
- #[ inline( always) ]
1222
- fn set_attrlist_with_times (
1223
- times : & FileTimes ,
1224
- ) -> io:: Result < ( libc:: attrlist , [ mem:: MaybeUninit < libc:: timespec > ; 3 ] , usize ) > {
1225
- let mut buf = [ mem:: MaybeUninit :: < libc:: timespec > :: uninit ( ) ; 3 ] ;
1226
- let mut num_times = 0 ;
1227
- let mut attrlist: libc:: attrlist = unsafe { mem:: zeroed ( ) } ;
1228
- attrlist. bitmapcount = libc:: ATTR_BIT_MAP_COUNT ;
1229
-
1230
- if times. created . is_some ( ) {
1231
- buf[ num_times] . write ( to_timespec ( times. created ) ?) ;
1232
- num_times += 1 ;
1233
- attrlist. commonattr |= libc:: ATTR_CMN_CRTIME ;
1234
- }
1235
- if times. modified . is_some ( ) {
1236
- buf[ num_times] . write ( to_timespec ( times. modified ) ?) ;
1237
- num_times += 1 ;
1238
- attrlist. commonattr |= libc:: ATTR_CMN_MODTIME ;
1239
- }
1240
- if times. accessed . is_some ( ) {
1241
- buf[ num_times] . write ( to_timespec ( times. accessed ) ?) ;
1242
- num_times += 1 ;
1243
- attrlist. commonattr |= libc:: ATTR_CMN_ACCTIME ;
1244
- }
1245
-
1246
- Ok ( ( attrlist, buf, num_times) )
1247
- }
1248
-
1249
1198
impl File {
1250
1199
pub fn open ( path : & Path , opts : & OpenOptions ) -> io:: Result < File > {
1251
1200
run_path_with_cstr ( path, & |path| File :: open_c ( path, opts) )
@@ -1760,18 +1709,19 @@ impl TimesAttrlist {
1760
1709
if times. created . is_some ( ) {
1761
1710
this. buf [ this. num_times ] . write ( file_time_to_timespec ( times. created ) ?) ;
1762
1711
this. num_times += 1 ;
1763
- attrlist. commonattr |= libc:: ATTR_CMN_CRTIME ;
1712
+ this . attrlist . commonattr |= libc:: ATTR_CMN_CRTIME ;
1764
1713
}
1765
1714
if times. modified . is_some ( ) {
1766
1715
this. buf [ this. num_times ] . write ( file_time_to_timespec ( times. modified ) ?) ;
1767
1716
this. num_times += 1 ;
1768
- attrlist. commonattr |= libc:: ATTR_CMN_MODTIME ;
1717
+ this . attrlist . commonattr |= libc:: ATTR_CMN_MODTIME ;
1769
1718
}
1770
1719
if times. accessed . is_some ( ) {
1771
1720
this. buf [ this. num_times ] . write ( file_time_to_timespec ( times. accessed ) ?) ;
1772
1721
this. num_times += 1 ;
1773
- attrlist. commonattr |= libc:: ATTR_CMN_ACCTIME ;
1722
+ this . attrlist . commonattr |= libc:: ATTR_CMN_ACCTIME ;
1774
1723
}
1724
+ Ok ( this)
1775
1725
}
1776
1726
1777
1727
fn attrlist ( & self ) -> * mut libc:: c_void {
@@ -2174,7 +2124,8 @@ fn set_times_impl(p: &CStr, times: FileTimes, flags: c_int) -> io::Result<()> {
2174
2124
}
2175
2125
target_vendor = "apple" => {
2176
2126
// Apple platforms use setattrlist which supports setting times on symlinks
2177
- let ( attrlist, buf, num_times) = set_attrlist_with_times( & times) ?;
2127
+ //let (attrlist, buf, num_times) = set_attrlist_with_times(×)?;
2128
+ let ta = TimesAttrlist :: from_times( & times) ?;
2178
2129
let options = if flags == libc:: AT_SYMLINK_NOFOLLOW {
2179
2130
libc:: FSOPT_NOFOLLOW
2180
2131
} else {
@@ -2183,15 +2134,15 @@ fn set_times_impl(p: &CStr, times: FileTimes, flags: c_int) -> io::Result<()> {
2183
2134
2184
2135
cvt( unsafe { libc:: setattrlist(
2185
2136
p. as_ptr( ) ,
2186
- ( & raw const attrlist ) . cast :: <libc :: c_void> ( ) . cast_mut ( ) ,
2187
- buf . as_ptr ( ) . cast :: <libc :: c_void> ( ) . cast_mut ( ) ,
2188
- num_times * size_of :: <libc :: timespec> ( ) ,
2137
+ ta . attrlist ( ) ,
2138
+ ta . times_buf ( ) ,
2139
+ ta . times_buf_size ( ) ,
2189
2140
options as u32
2190
2141
) } ) ?;
2191
2142
Ok ( ( ) )
2192
2143
}
2193
2144
target_os = "android" => {
2194
- let times = [ to_timespec ( times. accessed) ?, to_timespec ( times. modified) ?] ;
2145
+ let times = [ file_time_to_timespec ( times. accessed) ?, file_time_to_timespec ( times. modified) ?] ;
2195
2146
// utimensat requires Android API level 19
2196
2147
cvt( unsafe {
2197
2148
weak!(
@@ -2225,18 +2176,20 @@ fn set_times_impl(p: &CStr, times: FileTimes, flags: c_int) -> io::Result<()> {
2225
2176
return Ok ( ( ) ) ;
2226
2177
}
2227
2178
}
2228
- let times = [ to_timespec ( times. accessed) ?, to_timespec ( times. modified) ?] ;
2179
+ let times = [ file_time_to_timespec ( times. accessed) ?, file_time_to_timespec ( times. modified) ?] ;
2229
2180
cvt( unsafe { libc:: utimensat( libc:: AT_FDCWD , p. as_ptr( ) , times. as_ptr( ) , flags) } ) ?;
2230
2181
Ok ( ( ) )
2231
2182
}
2232
2183
}
2233
2184
}
2234
2185
2186
+ #[ inline( always) ]
2235
2187
pub fn set_times ( p : & CStr , times : FileTimes ) -> io:: Result < ( ) > {
2236
2188
// flags = 0 means follow symlinks
2237
2189
set_times_impl ( p, times, 0 )
2238
2190
}
2239
2191
2192
+ #[ inline( always) ]
2240
2193
pub fn set_times_nofollow ( p : & CStr , times : FileTimes ) -> io:: Result < ( ) > {
2241
2194
set_times_impl ( p, times, libc:: AT_SYMLINK_NOFOLLOW )
2242
2195
}
0 commit comments