From e45577e097b064797def3554468cffa5fdd443d3 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Thu, 6 Oct 2022 20:20:17 -0700 Subject: [PATCH] feat(wasi) add `push_file` and `push_dir` methods to `WasiCtx` (#5027) These are useful when we don't want to collide with an existing file descriptor. --- crates/wasi-common/src/ctx.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/wasi-common/src/ctx.rs b/crates/wasi-common/src/ctx.rs index f99a9f7ed6..b4b3a55324 100644 --- a/crates/wasi-common/src/ctx.rs +++ b/crates/wasi-common/src/ctx.rs @@ -43,6 +43,10 @@ impl WasiCtx { .insert_at(fd, Box::new(FileEntry::new(caps, file))); } + pub fn push_file(&mut self, file: Box, caps: FileCaps) -> Result { + self.table().push(Box::new(FileEntry::new(caps, file))) + } + pub fn insert_dir( &mut self, fd: u32, @@ -57,6 +61,17 @@ impl WasiCtx { ); } + pub fn push_dir( + &mut self, + dir: Box, + caps: DirCaps, + file_caps: FileCaps, + path: PathBuf, + ) -> Result { + self.table() + .push(Box::new(DirEntry::new(caps, file_caps, Some(path), dir))) + } + pub fn table(&mut self) -> &mut Table { &mut self.table }