Browse Source

cap-std-sync: test opening a tempdir as ambient and then WasiDir

pull/2629/head
Pat Hickey 4 years ago
parent
commit
a4372c8c2e
  1. 1
      Cargo.lock
  2. 3
      crates/wasi-common/cap-std-sync/Cargo.toml
  3. 19
      crates/wasi-common/cap-std-sync/src/dir.rs

1
Cargo.lock

@ -3075,6 +3075,7 @@ dependencies = [
"lazy_static",
"libc",
"system-interface",
"tempfile",
"tracing",
"unsafe-io",
"wasi-common",

3
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"

19
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<wasi_common::SystemTimeSpec>) -> Option<SystemT
None => 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");
}
}

Loading…
Cancel
Save