set_fd_flags is only good for append and nonblock
This commit is contained in:
@@ -65,21 +65,15 @@ impl WasiDir for Dir {
|
|||||||
} else {
|
} else {
|
||||||
opts.follow(FollowSymlinks::No);
|
opts.follow(FollowSymlinks::No);
|
||||||
}
|
}
|
||||||
|
// the DSYNC, SYNC, and RSYNC flags are ignored! We do not
|
||||||
let mut f = self.0.open_with(Path::new(path), &opts)?;
|
// have support for them in cap-std yet.
|
||||||
// This takes care of setting the fdflags that can't be handled by OpenOptions (yet)
|
|
||||||
// (DSYNC, SYNC, NONBLOCK, RSYNC)
|
|
||||||
// ideally OpenOptions would just support this though:
|
// ideally OpenOptions would just support this though:
|
||||||
// https://github.com/bytecodealliance/cap-std/issues/146
|
// https://github.com/bytecodealliance/cap-std/issues/146
|
||||||
{
|
|
||||||
// Even worse - set_fd_flags panicks when given DSYNC, SYNC, RSYNC!
|
let mut f = self.0.open_with(Path::new(path), &opts)?;
|
||||||
// it only supports NONBLOCK
|
// NONBLOCK does not have an OpenOption either, but we can patch that on with set_fd_flags:
|
||||||
let fdflags = if fdflags.contains(wasi_common::file::FdFlags::NONBLOCK) {
|
if fdflags.contains(wasi_common::file::FdFlags::NONBLOCK) {
|
||||||
system_interface::fs::FdFlags::NONBLOCK
|
f.set_fd_flags(system_interface::fs::FdFlags::NONBLOCK)?;
|
||||||
} else {
|
|
||||||
system_interface::fs::FdFlags::empty()
|
|
||||||
};
|
|
||||||
f.set_fd_flags(fdflags)?;
|
|
||||||
}
|
}
|
||||||
Ok(Box::new(File::from_cap_std(f)))
|
Ok(Box::new(File::from_cap_std(f)))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use system_interface::{
|
|||||||
};
|
};
|
||||||
use wasi_common::{
|
use wasi_common::{
|
||||||
file::{Advice, FdFlags, FileType, Filestat, WasiFile},
|
file::{Advice, FdFlags, FileType, Filestat, WasiFile},
|
||||||
Error,
|
Error, ErrorExt,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub struct File(cap_std::fs::File);
|
pub struct File(cap_std::fs::File);
|
||||||
@@ -41,6 +41,13 @@ impl WasiFile for File {
|
|||||||
Ok(from_sysif_fdflags(fdflags))
|
Ok(from_sysif_fdflags(fdflags))
|
||||||
}
|
}
|
||||||
fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> {
|
fn set_fdflags(&mut self, fdflags: FdFlags) -> Result<(), Error> {
|
||||||
|
if fdflags.intersects(
|
||||||
|
wasi_common::file::FdFlags::DSYNC
|
||||||
|
| wasi_common::file::FdFlags::SYNC
|
||||||
|
| wasi_common::file::FdFlags::RSYNC,
|
||||||
|
) {
|
||||||
|
return Err(Error::invalid_argument().context("cannot set DSYNC, SYNC, or RSYNC flag"));
|
||||||
|
}
|
||||||
Ok(self.0.set_fd_flags(to_sysif_fdflags(fdflags))?)
|
Ok(self.0.set_fd_flags(to_sysif_fdflags(fdflags))?)
|
||||||
}
|
}
|
||||||
fn get_filestat(&self) -> Result<Filestat, Error> {
|
fn get_filestat(&self) -> Result<Filestat, Error> {
|
||||||
|
|||||||
Reference in New Issue
Block a user