@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
2
2
use std:: convert:: { TryFrom , TryInto } ;
3
3
use std:: fs:: { read_dir, remove_dir, remove_file, rename, DirBuilder , File , FileType , OpenOptions , ReadDir } ;
4
4
use std:: io:: { Read , Seek , SeekFrom , Write } ;
5
- use std:: path:: PathBuf ;
5
+ use std:: path:: Path ;
6
6
use std:: time:: SystemTime ;
7
7
8
8
use rustc_data_structures:: fx:: FxHashMap ;
@@ -79,9 +79,9 @@ trait EvalContextExtPrivate<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, '
79
79
let this = self . eval_context_mut ( ) ;
80
80
81
81
let path_scalar = this. read_scalar ( path_op) ?. not_undef ( ) ?;
82
- let path: PathBuf = this. read_os_str_from_c_str ( path_scalar) ?. into ( ) ;
82
+ let path = this. read_path_from_c_str ( path_scalar) ?. into_owned ( ) ;
83
83
84
- let metadata = match FileMetadata :: from_path ( this, path, follow_symlink) ? {
84
+ let metadata = match FileMetadata :: from_path ( this, & path, follow_symlink) ? {
85
85
Some ( metadata) => metadata,
86
86
None => return Ok ( -1 ) ,
87
87
} ;
@@ -303,7 +303,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
303
303
throw_unsup_format ! ( "unsupported flags {:#x}" , flag & !mirror) ;
304
304
}
305
305
306
- let path = this. read_os_str_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
306
+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
307
307
308
308
let fd = options. open ( & path) . map ( |file| {
309
309
let fh = & mut this. machine . file_handler ;
@@ -524,10 +524,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
524
524
525
525
this. check_no_isolation ( "unlink" ) ?;
526
526
527
- let path = this. read_os_str_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
527
+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
528
528
529
529
let result = remove_file ( path) . map ( |_| 0 ) ;
530
-
531
530
this. try_unwrap_io_result ( result)
532
531
}
533
532
@@ -537,12 +536,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
537
536
linkpath_op : OpTy < ' tcx , Tag >
538
537
) -> InterpResult < ' tcx , i32 > {
539
538
#[ cfg( target_family = "unix" ) ]
540
- fn create_link ( src : PathBuf , dst : PathBuf ) -> std:: io:: Result < ( ) > {
539
+ fn create_link ( src : & Path , dst : & Path ) -> std:: io:: Result < ( ) > {
541
540
std:: os:: unix:: fs:: symlink ( src, dst)
542
541
}
543
542
544
543
#[ cfg( target_family = "windows" ) ]
545
- fn create_link ( src : PathBuf , dst : PathBuf ) -> std:: io:: Result < ( ) > {
544
+ fn create_link ( src : & Path , dst : & Path ) -> std:: io:: Result < ( ) > {
546
545
use std:: os:: windows:: fs;
547
546
if src. is_dir ( ) {
548
547
fs:: symlink_dir ( src, dst)
@@ -555,10 +554,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
555
554
556
555
this. check_no_isolation ( "symlink" ) ?;
557
556
558
- let target = this. read_os_str_from_c_str ( this. read_scalar ( target_op) ?. not_undef ( ) ?) ?. into ( ) ;
559
- let linkpath = this. read_os_str_from_c_str ( this. read_scalar ( linkpath_op) ?. not_undef ( ) ?) ?. into ( ) ;
557
+ let target = this. read_path_from_c_str ( this. read_scalar ( target_op) ?. not_undef ( ) ?) ?;
558
+ let linkpath = this. read_path_from_c_str ( this. read_scalar ( linkpath_op) ?. not_undef ( ) ?) ?;
560
559
561
- this. try_unwrap_io_result ( create_link ( target, linkpath) . map ( |_| 0 ) )
560
+ let result = create_link ( & target, & linkpath) . map ( |_| 0 ) ;
561
+ this. try_unwrap_io_result ( result)
562
562
}
563
563
564
564
fn macos_stat (
@@ -644,7 +644,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
644
644
this. ref_to_mplace ( statxbuf_imm) ?
645
645
} ;
646
646
647
- let path: PathBuf = this. read_os_str_from_c_str ( pathname_scalar) ?. into ( ) ;
647
+ let path = this. read_path_from_c_str ( pathname_scalar) ?. into_owned ( ) ;
648
648
// `flags` should be a `c_int` but the `syscall` function provides an `isize`.
649
649
let flags: i32 =
650
650
this. read_scalar ( flags_op) ?. to_machine_isize ( & * this. tcx ) ?. try_into ( ) . map_err ( |e| {
@@ -691,7 +691,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
691
691
let metadata = if path. as_os_str ( ) . is_empty ( ) && empty_path_flag {
692
692
FileMetadata :: from_fd ( this, dirfd) ?
693
693
} else {
694
- FileMetadata :: from_path ( this, path, follow_symlink) ?
694
+ FileMetadata :: from_path ( this, & path, follow_symlink) ?
695
695
} ;
696
696
let metadata = match metadata {
697
697
Some ( metadata) => metadata,
@@ -785,8 +785,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
785
785
return Ok ( -1 ) ;
786
786
}
787
787
788
- let oldpath = this. read_os_str_from_c_str ( oldpath_scalar) ?;
789
- let newpath = this. read_os_str_from_c_str ( newpath_scalar) ?;
788
+ let oldpath = this. read_path_from_c_str ( oldpath_scalar) ?;
789
+ let newpath = this. read_path_from_c_str ( newpath_scalar) ?;
790
790
791
791
let result = rename ( oldpath, newpath) . map ( |_| 0 ) ;
792
792
@@ -808,7 +808,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
808
808
this. read_scalar ( mode_op) ?. to_u32 ( ) ?
809
809
} ;
810
810
811
- let path = this. read_os_str_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
811
+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
812
812
813
813
let mut builder = DirBuilder :: new ( ) ;
814
814
@@ -833,7 +833,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
833
833
834
834
this. check_no_isolation ( "rmdir" ) ?;
835
835
836
- let path = this. read_os_str_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
836
+ let path = this. read_path_from_c_str ( this. read_scalar ( path_op) ?. not_undef ( ) ?) ?;
837
837
838
838
let result = remove_dir ( path) . map ( |_| 0i32 ) ;
839
839
@@ -845,7 +845,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
845
845
846
846
this. check_no_isolation ( "opendir" ) ?;
847
847
848
- let name = this. read_os_str_from_c_str ( this. read_scalar ( name_op) ?. not_undef ( ) ?) ?;
848
+ let name = this. read_path_from_c_str ( this. read_scalar ( name_op) ?. not_undef ( ) ?) ?;
849
849
850
850
let result = read_dir ( name) ;
851
851
@@ -899,7 +899,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
899
899
let entry_place = this. deref_operand ( entry_op) ?;
900
900
let name_place = this. mplace_field ( entry_place, 4 ) ?;
901
901
902
- let file_name = dir_entry. file_name ( ) ;
902
+ let file_name = dir_entry. file_name ( ) ; // not a Path as there are no separators!
903
903
let ( name_fits, _) = this. write_os_str_to_c_str (
904
904
& file_name,
905
905
name_place. ptr ,
@@ -987,7 +987,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
987
987
let entry_place = this. deref_operand ( entry_op) ?;
988
988
let name_place = this. mplace_field ( entry_place, 5 ) ?;
989
989
990
- let file_name = dir_entry. file_name ( ) ;
990
+ let file_name = dir_entry. file_name ( ) ; // not a Path as there are no separators!
991
991
let ( name_fits, file_name_len) = this. write_os_str_to_c_str (
992
992
& file_name,
993
993
name_place. ptr ,
@@ -1082,7 +1082,7 @@ struct FileMetadata {
1082
1082
impl FileMetadata {
1083
1083
fn from_path < ' tcx , ' mir > (
1084
1084
ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
1085
- path : PathBuf ,
1085
+ path : & Path ,
1086
1086
follow_symlink : bool
1087
1087
) -> InterpResult < ' tcx , Option < FileMetadata > > {
1088
1088
let metadata = if follow_symlink {
0 commit comments