open_file requires the FdFlags

This commit is contained in:
Pat Hickey
2020-12-18 16:56:58 -08:00
parent a33418c34a
commit 8672dce541
2 changed files with 13 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
use crate::error::Error;
use crate::file::{FileCaps, FileType, Filestat, OFlags, WasiFile};
use crate::file::{FdFlags, FileCaps, FileType, Filestat, OFlags, WasiFile};
use std::convert::TryInto;
use std::ops::Deref;
use std::path::{Path, PathBuf};
@@ -11,6 +11,7 @@ pub trait WasiDir {
path: &str,
oflags: OFlags,
caps: FileCaps,
fdflags: FdFlags,
) -> Result<Box<dyn WasiFile>, Error>;
fn open_dir(&self, symlink_follow: bool, path: &str) -> Result<Box<dyn WasiDir>, Error>;
fn create_dir(&self, path: &str) -> Result<(), Error>;
@@ -201,6 +202,7 @@ impl WasiDir for cap_std::fs::Dir {
path: &str,
oflags: OFlags,
caps: FileCaps,
fdflags: FdFlags,
) -> Result<Box<dyn WasiFile>, Error> {
use cap_fs_ext::{FollowSymlinks, OpenOptionsFollowExt};
@@ -231,6 +233,12 @@ impl WasiDir for cap_std::fs::Dir {
if caps.contains(&FileCaps::READ) {
opts.read(true);
}
if fdflags.contains(&FdFlags::APPEND) {
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 {
opts.follow(FollowSymlinks::Yes);

View File

@@ -519,11 +519,12 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
let table = self.table();
let file_entry: Ref<FileEntry> = table.get(u32::from(fd))?;
let f = file_entry.get_cap(required_caps)?;
let newoffset = f.seek(match whence {
let whence = match whence {
types::Whence::Cur => SeekFrom::Current(offset),
types::Whence::End => SeekFrom::End(offset),
types::Whence::Set => SeekFrom::Start(offset as u64),
})?;
};
let newoffset = f.seek(whence)?;
Ok(newoffset)
}
@@ -694,7 +695,7 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
let dir = dir_entry.get_cap(required_caps)?;
let file_caps = dir_entry.child_file_caps(FileCaps::from(&fs_rights_base));
let file = dir.open_file(symlink_follow, path.deref(), oflags, file_caps)?;
let file = dir.open_file(symlink_follow, path.deref(), oflags, file_caps, fdflags)?;
drop(dir);
drop(dir_entry);
let fd = table.push(Box::new(FileEntry::new(file_caps, file)))?;