cap-std-sync: test opening a tempdir as ambient and then WasiDir
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -3075,6 +3075,7 @@ dependencies = [
|
||||
"lazy_static",
|
||||
"libc",
|
||||
"system-interface",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
"unsafe-io",
|
||||
"wasi-common",
|
||||
|
||||
@@ -31,3 +31,6 @@ libc = "0.2"
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
winapi = "0.3"
|
||||
lazy_static = "1.4"
|
||||
|
||||
[dev-dependencies]
|
||||
tempfile = "3.1.0"
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user