set_fd_flags is only good for append and nonblock

This commit is contained in:
Pat Hickey
2021-02-01 14:14:13 -08:00
parent 5ee093e774
commit 993697e221
2 changed files with 15 additions and 14 deletions

View File

@@ -65,21 +65,15 @@ impl WasiDir for Dir {
} else {
opts.follow(FollowSymlinks::No);
}
let mut f = self.0.open_with(Path::new(path), &opts)?;
// This takes care of setting the fdflags that can't be handled by OpenOptions (yet)
// (DSYNC, SYNC, NONBLOCK, RSYNC)
// the DSYNC, SYNC, and RSYNC flags are ignored! We do not
// have support for them in cap-std yet.
// ideally OpenOptions would just support this though:
// https://github.com/bytecodealliance/cap-std/issues/146
{
// Even worse - set_fd_flags panicks when given DSYNC, SYNC, RSYNC!
// it only supports NONBLOCK
let fdflags = if fdflags.contains(wasi_common::file::FdFlags::NONBLOCK) {
system_interface::fs::FdFlags::NONBLOCK
} else {
system_interface::fs::FdFlags::empty()
};
f.set_fd_flags(fdflags)?;
let mut f = self.0.open_with(Path::new(path), &opts)?;
// NONBLOCK does not have an OpenOption either, but we can patch that on with set_fd_flags:
if fdflags.contains(wasi_common::file::FdFlags::NONBLOCK) {
f.set_fd_flags(system_interface::fs::FdFlags::NONBLOCK)?;
}
Ok(Box::new(File::from_cap_std(f)))
}