@@ -84,8 +84,8 @@ pub struct FilePermissions {
84
84
85
85
#[ derive( Copy , Clone , Debug , Default ) ]
86
86
pub struct FileTimes {
87
- accessed : c:: FILETIME ,
88
- modified : c:: FILETIME ,
87
+ accessed : Option < c:: FILETIME > ,
88
+ modified : Option < c:: FILETIME > ,
89
89
}
90
90
91
91
#[ derive( Debug ) ]
@@ -558,8 +558,15 @@ impl File {
558
558
}
559
559
560
560
pub fn set_times ( & self , times : FileTimes ) -> io:: Result < ( ) > {
561
+ let is_zero = |t : c:: FILETIME | t. dwLowDateTime == 0 && t. dwHighDateTime == 0 ;
562
+ if times. accessed . map_or ( false , is_zero) || times. modified . map_or ( false , is_zero) {
563
+ return Err ( io:: const_io_error!(
564
+ io:: ErrorKind :: InvalidInput ,
565
+ "Cannot set file timestamp to 0" ,
566
+ ) ) ;
567
+ }
561
568
cvt ( unsafe {
562
- c:: SetFileTime ( self . as_handle ( ) , None , Some ( & times. accessed ) , Some ( & times. modified ) )
569
+ c:: SetFileTime ( self . as_handle ( ) , None , times. accessed . as_ref ( ) , times. modified . as_ref ( ) )
563
570
} ) ?;
564
571
Ok ( ( ) )
565
572
}
@@ -911,11 +918,11 @@ impl FilePermissions {
911
918
912
919
impl FileTimes {
913
920
pub fn set_accessed ( & mut self , t : SystemTime ) {
914
- self . accessed = t. into_inner ( ) ;
921
+ self . accessed = Some ( t. into_inner ( ) ) ;
915
922
}
916
923
917
924
pub fn set_modified ( & mut self , t : SystemTime ) {
918
- self . modified = t. into_inner ( ) ;
925
+ self . modified = Some ( t. into_inner ( ) ) ;
919
926
}
920
927
}
921
928
0 commit comments