From a4372c8c2e8192b1ff752ee6c7b5b0d47986962b Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Mon, 1 Feb 2021 13:15:39 -0800 Subject: [PATCH] cap-std-sync: test opening a tempdir as ambient and then WasiDir --- Cargo.lock | 1 + crates/wasi-common/cap-std-sync/Cargo.toml | 3 +++ crates/wasi-common/cap-std-sync/src/dir.rs | 19 ++++++++++++++++++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 93e3572b5a..e2b792cf94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3075,6 +3075,7 @@ dependencies = [ "lazy_static", "libc", "system-interface", + "tempfile", "tracing", "unsafe-io", "wasi-common", diff --git a/crates/wasi-common/cap-std-sync/Cargo.toml b/crates/wasi-common/cap-std-sync/Cargo.toml index 17320baf17..534b6dee67 100644 --- a/crates/wasi-common/cap-std-sync/Cargo.toml +++ b/crates/wasi-common/cap-std-sync/Cargo.toml @@ -31,3 +31,6 @@ libc = "0.2" [target.'cfg(windows)'.dependencies] winapi = "0.3" lazy_static = "1.4" + +[dev-dependencies] +tempfile = "3.1.0" diff --git a/crates/wasi-common/cap-std-sync/src/dir.rs b/crates/wasi-common/cap-std-sync/src/dir.rs index 1c75173c70..3ba290d508 100644 --- a/crates/wasi-common/cap-std-sync/src/dir.rs +++ b/crates/wasi-common/cap-std-sync/src/dir.rs @@ -1,4 +1,4 @@ -use crate::file::{filetype_from, to_sysif_fdflags, File}; +use crate::file::{filetype_from, File}; use cap_fs_ext::{DirExt, MetadataExt, SystemTimeSpec}; use std::any::Any; use std::convert::TryInto; @@ -256,3 +256,20 @@ fn convert_systimespec(t: Option) -> Option None, } } + +#[cfg(test)] +mod test { + use super::Dir; + #[test] + fn scratch_dir() { + let tempdir = tempfile::Builder::new() + .prefix("cap-std-sync") + .tempdir() + .expect("create temporary dir"); + let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(tempdir.path()) } + .expect("open ambient temporary dir"); + let preopen_dir = Dir::from_cap_std(preopen_dir); + wasi_common::WasiDir::open_dir(&preopen_dir, false, ".") + .expect("open the same directory via WasiDir abstraction"); + } +}