@@ -587,6 +587,21 @@ pub fn rmdir_recursive(path: &Path) {
587
587
rmdir ( path) ;
588
588
}
589
589
590
+ /// Changes the timestamps for a file's last modification and access time.
591
+ /// The file at the path specified will have its last access time set to
592
+ /// `atime` and its modification time set to `mtime`.
593
+ ///
594
+ /// # Errors
595
+ ///
596
+ /// This function will raise on the `io_error` condition if an error
597
+ /// happens.
598
+ // FIXME(#10301) these arguments should not be u64
599
+ pub fn change_file_times ( path : & Path , atime : u64 , mtime : u64 ) {
600
+ do io_raise |io| {
601
+ io. fs_utime ( & path. to_c_str ( ) , atime, mtime)
602
+ } ;
603
+ }
604
+
590
605
impl Reader for File {
591
606
fn read ( & mut self , buf : & mut [ u8 ] ) -> Option < uint > {
592
607
match self . fd . read ( buf) {
@@ -704,8 +719,8 @@ mod test {
704
719
use rt:: io;
705
720
use str;
706
721
use super :: { File , rmdir, mkdir, readdir, rmdir_recursive, mkdir_recursive,
707
- copy, unlink, stat, symlink, link, readlink, chmod, chown ,
708
- lstat} ;
722
+ copy, unlink, stat, symlink, link, readlink, chmod,
723
+ lstat, change_file_times } ;
709
724
710
725
fn tmpdir ( ) -> Path {
711
726
use os;
@@ -1244,4 +1259,29 @@ mod test {
1244
1259
1245
1260
rmdir_recursive ( & tmpdir) ;
1246
1261
}
1262
+
1263
+ #[ test]
1264
+ fn utime ( ) {
1265
+ let tmpdir = tmpdir ( ) ;
1266
+ let path = tmpdir. join ( "a" ) ;
1267
+ File :: create ( & path) ;
1268
+
1269
+ change_file_times ( & path, 100 , 200 ) ;
1270
+ assert_eq ! ( path. stat( ) . accessed, 100 ) ;
1271
+ assert_eq ! ( path. stat( ) . modified, 200 ) ;
1272
+
1273
+ rmdir_recursive ( & tmpdir) ;
1274
+ }
1275
+
1276
+ #[ test]
1277
+ fn utime_noexist ( ) {
1278
+ let tmpdir = tmpdir ( ) ;
1279
+
1280
+ match io:: result ( || change_file_times ( & tmpdir. join ( "a" ) , 100 , 200 ) ) {
1281
+ Ok ( * ) => fail ! ( ) ,
1282
+ Err ( * ) => { }
1283
+ }
1284
+
1285
+ rmdir_recursive ( & tmpdir) ;
1286
+ }
1247
1287
}
0 commit comments