cap-std-sync Dir::open_file: set the fdflags that OpenOptions cant

This commit is contained in:
Pat Hickey
2021-01-29 21:08:53 -08:00
parent 3d406ff50e
commit e9a7a4094c

View File

@@ -1,8 +1,9 @@
use crate::file::{filetype_from, File}; use crate::file::{filetype_from, to_sysif_fdflags, File};
use cap_fs_ext::{DirExt, MetadataExt, SystemTimeSpec}; use cap_fs_ext::{DirExt, MetadataExt, SystemTimeSpec};
use std::any::Any; use std::any::Any;
use std::convert::TryInto; use std::convert::TryInto;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use system_interface::fs::GetSetFdFlags;
use wasi_common::{ use wasi_common::{
dir::{ReaddirCursor, ReaddirEntity, WasiDir}, dir::{ReaddirCursor, ReaddirEntity, WasiDir},
file::{FdFlags, FileType, Filestat, OFlags, WasiFile}, file::{FdFlags, FileType, Filestat, OFlags, WasiFile},
@@ -58,9 +59,6 @@ impl WasiDir for Dir {
if fdflags.contains(FdFlags::APPEND) { if fdflags.contains(FdFlags::APPEND) {
opts.append(true); opts.append(true);
} }
// XXX what about rest of fdflags - dsync, sync become oflags.
// what do we do with nonblock?
// what do we do with rsync?
if symlink_follow { if symlink_follow {
opts.follow(FollowSymlinks::Yes); opts.follow(FollowSymlinks::Yes);
@@ -68,7 +66,12 @@ impl WasiDir for Dir {
opts.follow(FollowSymlinks::No); opts.follow(FollowSymlinks::No);
} }
let f = self.0.open_with(Path::new(path), &opts)?; 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)
// ideally OpenOptions would just support this though:
// https://github.com/bytecodealliance/cap-std/issues/146
f.set_fd_flags(to_sysif_fdflags(fdflags))?;
Ok(Box::new(File::from_cap_std(f))) Ok(Box::new(File::from_cap_std(f)))
} }