Skip to content

Commit

Permalink
add support for the tempfile crate
Browse files Browse the repository at this point in the history
  • Loading branch information
Pointerbender committed Dec 12, 2022
1 parent 1fca5a9 commit 6dcb99b
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,13 @@ 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);
// currently we only support that the owner must always have
// read-write permissions and that none of the owner, group
// and other may have execute permissions.
let owner_has_read_write_permissions = mode & 0o600 == 0o600;
let has_any_execute_permissions = mode & 0o111 != 0;
if !owner_has_read_write_permissions || has_any_execute_permissions {
throw_unsup_format!("mode 0o{:o} is not supported", mode);
}

mirror |= o_creat;
Expand Down
42 changes: 42 additions & 0 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 @@ -13,6 +13,7 @@ tokio = { version = "1.0", features = ["full"] }
libc = "0.2"
page_size = "0.5"
num_cpus = "1.10.1"
tempfile = "3"

getrandom_1 = { package = "getrandom", version = "0.1" }
getrandom = { version = "0.2" }
Expand Down
7 changes: 7 additions & 0 deletions tests/pass-dep/shims/libc-fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ fn main() {
test_file_open_unix_extra_third_arg();
#[cfg(target_os = "linux")]
test_o_tmpfile_flag();
test_tempfile();
}

fn tmp() -> PathBuf {
Expand Down Expand Up @@ -166,3 +167,9 @@ fn test_o_tmpfile_flag() {
.raw_os_error(),
);
}

/// Test that the [`tempfile`] crate is compatible with miri.
fn test_tempfile() {
let dir_path = tmp();
tempfile::tempfile_in(dir_path).unwrap();
}

0 comments on commit 6dcb99b

Please sign in to comment.