Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for tempfile crate on UNIX hosts #3240

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}