diff --git a/src/descriptors.rs b/src/descriptors.rs index 288a209921..036fd88ab7 100644 --- a/src/descriptors.rs +++ b/src/descriptors.rs @@ -175,6 +175,8 @@ impl Descriptors { output: Cell::new(None), type_: StreamType::File(File { fd: preopen.descriptor, + descriptor_type: crate::bindings::filesystem::get_type(preopen.descriptor) + .trapping_unwrap(), position: Cell::new(0), append: false, }), @@ -332,6 +334,8 @@ impl Descriptors { } pub fn get_dir(&self, fd: Fd) -> Result<&File, Errno> { + // FIXME: do we look at the StreamType::File(File { descriptor_type }) and make sure it + // really is a DescriptorType::Directory here? self.get_file_with_error(fd, wasi::ERRNO_NOTDIR) } diff --git a/src/lib.rs b/src/lib.rs index 630227bb76..be2448e9cb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1313,11 +1313,13 @@ pub unsafe extern "C" fn path_open( let mut ds = state.descriptors_mut(); let file = ds.get_dir(fd)?; let result = filesystem::open_at(file.fd, at_flags, path, o_flags, flags, mode)?; + let descriptor_type = filesystem::get_type(result)?; let desc = Descriptor::Streams(Streams { input: Cell::new(None), output: Cell::new(None), type_: StreamType::File(File { fd: result, + descriptor_type, position: Cell::new(0), append, }), @@ -2000,6 +2002,9 @@ pub struct File { /// The handle to the preview2 descriptor that this file is referencing. fd: filesystem::Descriptor, + /// The descriptor type, as supplied by filesystem::get_type at opening + descriptor_type: filesystem::DescriptorType, + /// The current-position pointer. position: Cell,