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.
This commit is contained in:
Adam C. Foltzer
2022-10-06 20:20:17 -07:00
committed by GitHub
parent 4f8b94163c
commit e45577e097

View File

@@ -43,6 +43,10 @@ impl WasiCtx {
.insert_at(fd, Box::new(FileEntry::new(caps, file)));
}
pub fn push_file(&mut self, file: Box<dyn WasiFile>, caps: FileCaps) -> Result<u32, Error> {
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<dyn WasiDir>,
caps: DirCaps,
file_caps: FileCaps,
path: PathBuf,
) -> Result<u32, Error> {
self.table()
.push(Box::new(DirEntry::new(caps, file_caps, Some(path), dir)))
}
pub fn table(&mut self) -> &mut Table {
&mut self.table
}