Browse Source

File: we need to have the DescriptorType around to handle certain corner cases

pull/6374/head
Pat Hickey 2 years ago
parent
commit
8a32f7dfe8
  1. 4
      src/descriptors.rs
  2. 5
      src/lib.rs

4
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)
}

5
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<filesystem::Filesize>,

Loading…
Cancel
Save