@@ -1604,24 +1604,6 @@ impl File {
1604
1604
}
1605
1605
1606
1606
pub fn set_times ( & self , times : FileTimes ) -> io:: Result < ( ) > {
1607
- #[ cfg( not( any(
1608
- target_os = "redox" ,
1609
- target_os = "espidf" ,
1610
- target_os = "horizon" ,
1611
- target_os = "nuttx" ,
1612
- ) ) ) ]
1613
- let to_timespec = |time : Option < SystemTime > | match time {
1614
- Some ( time) if let Some ( ts) = time. t . to_timespec ( ) => Ok ( ts) ,
1615
- Some ( time) if time > crate :: sys:: time:: UNIX_EPOCH => Err ( io:: const_error!(
1616
- io:: ErrorKind :: InvalidInput ,
1617
- "timestamp is too large to set as a file time" ,
1618
- ) ) ,
1619
- Some ( _) => Err ( io:: const_error!(
1620
- io:: ErrorKind :: InvalidInput ,
1621
- "timestamp is too small to set as a file time" ,
1622
- ) ) ,
1623
- None => Ok ( libc:: timespec { tv_sec : 0 , tv_nsec : libc:: UTIME_OMIT as _ } ) ,
1624
- } ;
1625
1607
cfg_select ! {
1626
1608
any( target_os = "redox" , target_os = "espidf" , target_os = "horizon" , target_os = "nuttx" ) => {
1627
1609
// Redox doesn't appear to support `UTIME_OMIT`.
@@ -1639,17 +1621,17 @@ impl File {
1639
1621
let mut attrlist: libc:: attrlist = unsafe { mem:: zeroed( ) } ;
1640
1622
attrlist. bitmapcount = libc:: ATTR_BIT_MAP_COUNT ;
1641
1623
if times. created. is_some( ) {
1642
- buf[ num_times] . write( to_timespec ( times. created) ?) ;
1624
+ buf[ num_times] . write( file_time_to_timespec ( times. created) ?) ;
1643
1625
num_times += 1 ;
1644
1626
attrlist. commonattr |= libc:: ATTR_CMN_CRTIME ;
1645
1627
}
1646
1628
if times. modified. is_some( ) {
1647
- buf[ num_times] . write( to_timespec ( times. modified) ?) ;
1629
+ buf[ num_times] . write( file_time_to_timespec ( times. modified) ?) ;
1648
1630
num_times += 1 ;
1649
1631
attrlist. commonattr |= libc:: ATTR_CMN_MODTIME ;
1650
1632
}
1651
1633
if times. accessed. is_some( ) {
1652
- buf[ num_times] . write( to_timespec ( times. accessed) ?) ;
1634
+ buf[ num_times] . write( file_time_to_timespec ( times. accessed) ?) ;
1653
1635
num_times += 1 ;
1654
1636
attrlist. commonattr |= libc:: ATTR_CMN_ACCTIME ;
1655
1637
}
@@ -1663,7 +1645,7 @@ impl File {
1663
1645
Ok ( ( ) )
1664
1646
}
1665
1647
target_os = "android" => {
1666
- let times = [ to_timespec ( times. accessed) ?, to_timespec ( times. modified) ?] ;
1648
+ let times = [ file_time_to_timespec ( times. accessed) ?, file_time_to_timespec ( times. modified) ?] ;
1667
1649
// futimens requires Android API level 19
1668
1650
cvt( unsafe {
1669
1651
weak!(
@@ -1697,14 +1679,35 @@ impl File {
1697
1679
return Ok ( ( ) ) ;
1698
1680
}
1699
1681
}
1700
- let times = [ to_timespec ( times. accessed) ?, to_timespec ( times. modified) ?] ;
1682
+ let times = [ file_time_to_timespec ( times. accessed) ?, file_time_to_timespec ( times. modified) ?] ;
1701
1683
cvt( unsafe { libc:: futimens( self . as_raw_fd( ) , times. as_ptr( ) ) } ) ?;
1702
1684
Ok ( ( ) )
1703
1685
}
1704
1686
}
1705
1687
}
1706
1688
}
1707
1689
1690
+ #[ cfg( not( any(
1691
+ target_os = "redox" ,
1692
+ target_os = "espidf" ,
1693
+ target_os = "horizon" ,
1694
+ target_os = "nuttx" ,
1695
+ ) ) ) ]
1696
+ fn file_time_to_timespec ( time : Option < SystemTime > ) -> io:: Result < libc:: timespec > {
1697
+ match time {
1698
+ Some ( time) if let Some ( ts) = time. t . to_timespec ( ) => Ok ( ts) ,
1699
+ Some ( time) if time > crate :: sys:: time:: UNIX_EPOCH => Err ( io:: const_error!(
1700
+ io:: ErrorKind :: InvalidInput ,
1701
+ "timestamp is too large to set as a file time" ,
1702
+ ) ) ,
1703
+ Some ( _) => Err ( io:: const_error!(
1704
+ io:: ErrorKind :: InvalidInput ,
1705
+ "timestamp is too small to set as a file time" ,
1706
+ ) ) ,
1707
+ None => Ok ( libc:: timespec { tv_sec : 0 , tv_nsec : libc:: UTIME_OMIT as _ } ) ,
1708
+ }
1709
+ } ;
1710
+
1708
1711
impl DirBuilder {
1709
1712
pub fn new ( ) -> DirBuilder {
1710
1713
DirBuilder { mode : 0o777 }
0 commit comments