Skip to content

Commit fe1a722

Browse files
committed
Auto merge of #3240 - Jefffrey:tempfile, r=RalfJung
Support for tempfile crate on UNIX hosts Reviving old PR: #2720 Attempted to apply the changes as suggested by #2720 (comment) To fix tempfile to work for UNIX targets only and fall back to previous behaviour of only supporting default mode for Windows targets
2 parents 11908a0 + 06add70 commit fe1a722

File tree

4 files changed

+181
-16
lines changed

4 files changed

+181
-16
lines changed

src/shims/unix/fs.rs

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

562-
if mode != 0o666 {
563-
throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
562+
#[cfg(unix)]
563+
{
564+
// Support all modes on UNIX host
565+
use std::os::unix::fs::OpenOptionsExt;
566+
options.mode(mode);
567+
}
568+
#[cfg(not(unix))]
569+
{
570+
// Only support default mode for non-UNIX (i.e. Windows) host
571+
if mode != 0o666 {
572+
throw_unsup_format!(
573+
"non-default mode 0o{:o} is not supported on non-Unix hosts",
574+
mode
575+
);
576+
}
564577
}
565578

566579
mirror |= o_creat;

test_dependencies/Cargo.lock

+144-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test_dependencies/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ edition = "2021"
1111
# all dependencies (and their transitive ones) listed here can be used in `tests/`.
1212
libc = "0.2"
1313
num_cpus = "1.10.1"
14+
tempfile = "3"
1415

1516
getrandom_01 = { package = "getrandom", version = "0.1" }
1617
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }

tests/pass-dep/tempfile.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ignore-target-windows: File handling is not implemented yet
2+
//@ignore-host-windows: Only supported for UNIX hosts
3+
//@compile-flags: -Zmiri-disable-isolation
4+
5+
#[path = "../utils/mod.rs"]
6+
mod utils;
7+
8+
/// Test that the [`tempfile`] crate is compatible with miri for UNIX hosts and targets
9+
fn main() {
10+
test_tempfile();
11+
test_tempfile_in();
12+
}
13+
14+
fn test_tempfile() {
15+
tempfile::tempfile().unwrap();
16+
}
17+
18+
fn test_tempfile_in() {
19+
let dir_path = utils::tmp();
20+
tempfile::tempfile_in(dir_path).unwrap();
21+
}

0 commit comments

Comments
 (0)