@@ -275,10 +275,47 @@ fn test_futimens() {
275
275
let fd = fcntl:: open ( & fullpath, fcntl:: OFlag :: empty ( ) , stat:: Mode :: empty ( ) )
276
276
. unwrap ( ) ;
277
277
278
- futimens ( fd, & TimeSpec :: seconds ( 10 ) , & TimeSpec :: seconds ( 20 ) ) . unwrap ( ) ;
278
+ futimens (
279
+ fd,
280
+ Some ( & TimeSpec :: seconds ( 10 ) ) ,
281
+ Some ( & TimeSpec :: seconds ( 20 ) ) ,
282
+ )
283
+ . unwrap ( ) ;
279
284
assert_times_eq ( 10 , 20 , & fs:: metadata ( & fullpath) . unwrap ( ) ) ;
280
285
}
281
286
287
+ #[ test]
288
+ #[ cfg( not( any( target_os = "redox" , target_os = "haiku" ) ) ) ]
289
+ fn test_futimens_unchanged ( ) {
290
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
291
+ let fullpath = tempdir. path ( ) . join ( "file" ) ;
292
+ drop ( File :: create ( & fullpath) . unwrap ( ) ) ;
293
+ let fd = fcntl:: open ( & fullpath, fcntl:: OFlag :: empty ( ) , stat:: Mode :: empty ( ) )
294
+ . unwrap ( ) ;
295
+
296
+ let old_atime = fs:: metadata ( fullpath. as_path ( ) )
297
+ . unwrap ( )
298
+ . accessed ( )
299
+ . unwrap ( ) ;
300
+ let old_mtime = fs:: metadata ( fullpath. as_path ( ) )
301
+ . unwrap ( )
302
+ . modified ( )
303
+ . unwrap ( ) ;
304
+
305
+ futimens ( fd, None , None ) . unwrap ( ) ;
306
+
307
+ let new_atime = fs:: metadata ( fullpath. as_path ( ) )
308
+ . unwrap ( )
309
+ . accessed ( )
310
+ . unwrap ( ) ;
311
+ let new_mtime = fs:: metadata ( fullpath. as_path ( ) )
312
+ . unwrap ( )
313
+ . modified ( )
314
+ . unwrap ( ) ;
315
+ assert_eq ! ( old_atime, new_atime) ;
316
+ assert_eq ! ( old_mtime, new_mtime) ;
317
+ }
318
+
282
319
#[ test]
283
320
#[ cfg( not( any( target_os = "redox" , target_os = "haiku" ) ) ) ]
284
321
fn test_utimensat ( ) {
@@ -295,8 +332,8 @@ fn test_utimensat() {
295
332
utimensat (
296
333
Some ( dirfd) ,
297
334
filename,
298
- & TimeSpec :: seconds ( 12345 ) ,
299
- & TimeSpec :: seconds ( 678 ) ,
335
+ Some ( & TimeSpec :: seconds ( 12345 ) ) ,
336
+ Some ( & TimeSpec :: seconds ( 678 ) ) ,
300
337
UtimensatFlags :: FollowSymlink ,
301
338
)
302
339
. unwrap ( ) ;
@@ -307,14 +344,54 @@ fn test_utimensat() {
307
344
utimensat (
308
345
None ,
309
346
filename,
310
- & TimeSpec :: seconds ( 500 ) ,
311
- & TimeSpec :: seconds ( 800 ) ,
347
+ Some ( & TimeSpec :: seconds ( 500 ) ) ,
348
+ Some ( & TimeSpec :: seconds ( 800 ) ) ,
312
349
UtimensatFlags :: FollowSymlink ,
313
350
)
314
351
. unwrap ( ) ;
315
352
assert_times_eq ( 500 , 800 , & fs:: metadata ( & fullpath) . unwrap ( ) ) ;
316
353
}
317
354
355
+ #[ test]
356
+ #[ cfg( not( any( target_os = "redox" , target_os = "haiku" ) ) ) ]
357
+ fn test_utimensat_unchanged ( ) {
358
+ let _dr = crate :: DirRestore :: new ( ) ;
359
+ let tempdir = tempfile:: tempdir ( ) . unwrap ( ) ;
360
+ let filename = "foo.txt" ;
361
+ let fullpath = tempdir. path ( ) . join ( filename) ;
362
+ drop ( File :: create ( & fullpath) . unwrap ( ) ) ;
363
+ let dirfd =
364
+ fcntl:: open ( tempdir. path ( ) , fcntl:: OFlag :: empty ( ) , stat:: Mode :: empty ( ) )
365
+ . unwrap ( ) ;
366
+
367
+ let old_atime = fs:: metadata ( fullpath. as_path ( ) )
368
+ . unwrap ( )
369
+ . accessed ( )
370
+ . unwrap ( ) ;
371
+ let old_mtime = fs:: metadata ( fullpath. as_path ( ) )
372
+ . unwrap ( )
373
+ . modified ( )
374
+ . unwrap ( ) ;
375
+ utimensat (
376
+ Some ( dirfd) ,
377
+ filename,
378
+ None ,
379
+ None ,
380
+ UtimensatFlags :: NoFollowSymlink ,
381
+ )
382
+ . unwrap ( ) ;
383
+ let new_atime = fs:: metadata ( fullpath. as_path ( ) )
384
+ . unwrap ( )
385
+ . accessed ( )
386
+ . unwrap ( ) ;
387
+ let new_mtime = fs:: metadata ( fullpath. as_path ( ) )
388
+ . unwrap ( )
389
+ . modified ( )
390
+ . unwrap ( ) ;
391
+ assert_eq ! ( old_atime, new_atime) ;
392
+ assert_eq ! ( old_mtime, new_mtime) ;
393
+ }
394
+
318
395
#[ test]
319
396
#[ cfg( not( target_os = "redox" ) ) ]
320
397
fn test_mkdirat_success_path ( ) {
0 commit comments