Skip to content

Commit

Permalink
Auto merge of #3240 - Jefffrey:tempfile, r=RalfJung
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Dec 27, 2023
2 parents 11908a0 + 06add70 commit fe1a722
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 16 deletions.
17 changes: 15 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,21 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
);
};

if mode != 0o666 {
throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
#[cfg(unix)]
{
// Support all modes on UNIX host
use std::os::unix::fs::OpenOptionsExt;
options.mode(mode);
}
#[cfg(not(unix))]
{
// Only support default mode for non-UNIX (i.e. Windows) host
if mode != 0o666 {
throw_unsup_format!(
"non-default mode 0o{:o} is not supported on non-Unix hosts",
mode
);
}
}

mirror |= o_creat;
Expand Down
158 changes: 144 additions & 14 deletions test_dependencies/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test_dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2021"
# all dependencies (and their transitive ones) listed here can be used in `tests/`.
libc = "0.2"
num_cpus = "1.10.1"
tempfile = "3"

getrandom_01 = { package = "getrandom", version = "0.1" }
getrandom_02 = { package = "getrandom", version = "0.2", features = ["js"] }
Expand Down
21 changes: 21 additions & 0 deletions tests/pass-dep/tempfile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//@ignore-target-windows: File handling is not implemented yet
//@ignore-host-windows: Only supported for UNIX hosts
//@compile-flags: -Zmiri-disable-isolation

#[path = "../utils/mod.rs"]
mod utils;

/// Test that the [`tempfile`] crate is compatible with miri for UNIX hosts and targets
fn main() {
test_tempfile();
test_tempfile_in();
}

fn test_tempfile() {
tempfile::tempfile().unwrap();
}

fn test_tempfile_in() {
let dir_path = utils::tmp();
tempfile::tempfile_in(dir_path).unwrap();
}

0 comments on commit fe1a722

Please sign in to comment.