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

View File

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