Skip to content

Commit 6ab7557

Browse files
committedDec 19, 2023
Fix tempfile to work for UNIX targets only
1 parent 79bec6d commit 6ab7557

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed
 

‎src/shims/unix/fs.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -559,13 +559,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
559559
);
560560
};
561561

562-
// currently we only support that the owner must always have
563-
// read-write permissions and that none of the owner, group
564-
// and other may have execute permissions.
565-
let owner_has_read_write_permissions = mode & 0o600 == 0o600;
566-
let has_any_execute_permissions = mode & 0o111 != 0;
567-
if !owner_has_read_write_permissions || has_any_execute_permissions {
568-
throw_unsup_format!("mode 0o{:o} is not supported", mode);
562+
match this.tcx.sess.target.os.as_ref() {
563+
// Support all modes on UNIX host
564+
"linux" | "freebsd" | "android" | "macos" => {}
565+
// Non-UNIX (aka Windows) only support default mode
566+
_ =>
567+
if mode != 0o666 {
568+
throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
569+
},
569570
}
570571

571572
mirror |= o_creat;

‎tests/pass-dep/tempfile.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66

77
/// Test that the [`tempfile`] crate is compatible with miri.
88
fn main() {
9-
// test_tempfile(); // does not work when host!=target
9+
test_tempfile();
1010
test_tempfile_in();
1111
}
1212

@@ -28,10 +28,9 @@ fn tmp() -> PathBuf {
2828
}
2929
}
3030

31-
// does not work when host!=target:
32-
// fn test_tempfile() {
33-
// tempfile::tempfile().unwrap();
34-
// }
31+
fn test_tempfile() {
32+
tempfile::tempfile().unwrap();
33+
}
3534

3635
fn test_tempfile_in() {
3736
let dir_path = tmp();

0 commit comments

Comments
 (0)