@@ -277,17 +277,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
277
277
278
278
let buf = this. deref_operand ( buf_op) ?;
279
279
280
- let stats = match FileStatus :: new ( this, path, false ) ? {
281
- Some ( stats ) => stats ,
280
+ let status = match FileStatus :: new ( this, path, false ) ? {
281
+ Some ( status ) => status ,
282
282
None => return Ok ( -1 ) ,
283
283
} ;
284
284
285
285
// FIXME: use Scalar::to_u16
286
- let mode: u16 = stats . mode . to_bits ( Size :: from_bits ( 16 ) ) ? as u16 ;
286
+ let mode: u16 = status . mode . to_bits ( Size :: from_bits ( 16 ) ) ? as u16 ;
287
287
288
- let ( access_sec, access_nsec) = stats . accessed . unwrap_or ( ( 0 , 0 ) ) ;
289
- let ( created_sec, created_nsec) = stats . created . unwrap_or ( ( 0 , 0 ) ) ;
290
- let ( modified_sec, modified_nsec) = stats . modified . unwrap_or ( ( 0 , 0 ) ) ;
288
+ let ( access_sec, access_nsec) = status . accessed . unwrap_or ( ( 0 , 0 ) ) ;
289
+ let ( created_sec, created_nsec) = status . created . unwrap_or ( ( 0 , 0 ) ) ;
290
+ let ( modified_sec, modified_nsec) = status . modified . unwrap_or ( ( 0 , 0 ) ) ;
291
291
292
292
let dev_t_layout = this. libc_ty_layout ( "dev_t" ) ?;
293
293
let mode_t_layout = this. libc_ty_layout ( "mode_t" ) ?;
@@ -326,7 +326,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
326
326
immty_from_uint_checked ( 0u128 , long_layout) ?, // st_ctime_nsec
327
327
immty_from_uint_checked ( created_sec, time_t_layout) ?, // st_birthtime
328
328
immty_from_uint_checked ( created_nsec, long_layout) ?, // st_birthtime_nsec
329
- immty_from_uint_checked ( stats . size , off_t_layout) ?, // st_size
329
+ immty_from_uint_checked ( status . size , off_t_layout) ?, // st_size
330
330
immty_from_uint_checked ( 0u128 , blkcnt_t_layout) ?, // st_blocks
331
331
immty_from_uint_checked ( 0u128 , blksize_t_layout) ?, // st_blksize
332
332
immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_flags
@@ -413,41 +413,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
413
413
// symbolic links.
414
414
let is_symlink = flags & this. eval_libc ( "AT_SYMLINK_NOFOLLOW" ) ?. to_i32 ( ) ? != 0 ;
415
415
416
- let stats = match FileStatus :: new ( this, path, is_symlink) ? {
417
- Some ( stats ) => stats ,
416
+ let status = match FileStatus :: new ( this, path, is_symlink) ? {
417
+ Some ( status ) => status ,
418
418
None => return Ok ( -1 ) ,
419
419
} ;
420
420
421
421
// The `mode` field specifies the type of the file and the permissions over the file for
422
422
// the owner, its group and other users. Given that we can only provide the file type
423
423
// without using platform specific methods, we only set the bits corresponding to the file
424
424
// type. This should be an `__u16` but `libc` provides its values as `u32`.
425
- let mode: u16 = stats
425
+ let mode: u16 = status
426
426
. mode
427
427
. to_u32 ( ) ?
428
428
. try_into ( )
429
429
. unwrap_or_else ( |_| bug ! ( "libc contains bad value for constant" ) ) ;
430
430
431
- let ( access_sec, access_nsec) = if let Some ( tup) = stats. accessed {
432
- tup
433
- } else {
431
+ let ( access_sec, access_nsec) = status. accessed . map ( |tup| {
434
432
mask |= this. eval_libc ( "STATX_ATIME" ) ?. to_u32 ( ) ?;
435
- ( 0 , 0 )
436
- } ;
433
+ InterpResult :: Ok ( tup )
434
+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
437
435
438
- let ( created_sec, created_nsec) = if let Some ( tup) = stats. created {
439
- tup
440
- } else {
436
+ let ( created_sec, created_nsec) = status. created . map ( |tup| {
441
437
mask |= this. eval_libc ( "STATX_BTIME" ) ?. to_u32 ( ) ?;
442
- ( 0 , 0 )
443
- } ;
438
+ InterpResult :: Ok ( tup )
439
+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
444
440
445
- let ( modified_sec, modified_nsec) = if let Some ( tup) = stats. modified {
446
- tup
447
- } else {
441
+ let ( modified_sec, modified_nsec) = status. modified . map ( |tup| {
448
442
mask |= this. eval_libc ( "STATX_MTIME" ) ?. to_u32 ( ) ?;
449
- ( 0 , 0 )
450
- } ;
443
+ InterpResult :: Ok ( tup )
444
+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
451
445
452
446
let __u32_layout = this. libc_ty_layout ( "__u32" ) ?;
453
447
let __u64_layout = this. libc_ty_layout ( "__u64" ) ?;
@@ -465,7 +459,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
465
459
immty_from_uint_checked ( mode, __u16_layout) ?, // stx_mode
466
460
immty_from_uint_checked ( 0u128 , __u16_layout) ?, // statx padding
467
461
immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_ino
468
- immty_from_uint_checked ( stats . size , __u64_layout) ?, // stx_size
462
+ immty_from_uint_checked ( status . size , __u64_layout) ?, // stx_size
469
463
immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_blocks
470
464
immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_attributes
471
465
immty_from_uint_checked ( access_sec, __u64_layout) ?, // stx_atime.tv_sec
@@ -521,7 +515,11 @@ struct FileStatus {
521
515
}
522
516
523
517
impl FileStatus {
524
- fn new < ' tcx , ' mir > ( ecx : & mut MiriEvalContext < ' mir , ' tcx > , path : PathBuf , is_symlink : bool ) -> InterpResult < ' tcx , Option < FileStatus > > {
518
+ fn new < ' tcx , ' mir > (
519
+ ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
520
+ path : PathBuf ,
521
+ is_symlink : bool
522
+ ) -> InterpResult < ' tcx , Option < FileStatus > > {
525
523
let metadata = if is_symlink {
526
524
// FIXME: metadata for symlinks need testing.
527
525
std:: fs:: symlink_metadata ( path)
0 commit comments