From 8672dce5411534a1ecf1aadd1dc3b84d5dd44a49 Mon Sep 17 00:00:00 2001 From: Pat Hickey Date: Fri, 18 Dec 2020 16:56:58 -0800 Subject: [PATCH] open_file requires the FdFlags --- crates/wasi-c2/src/dir.rs | 10 +++++++++- crates/wasi-c2/src/snapshots/preview_1.rs | 7 ++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/crates/wasi-c2/src/dir.rs b/crates/wasi-c2/src/dir.rs index 30902ae61e..ebae4d657b 100644 --- a/crates/wasi-c2/src/dir.rs +++ b/crates/wasi-c2/src/dir.rs @@ -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, Error>; fn open_dir(&self, symlink_follow: bool, 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, oflags: OFlags, caps: FileCaps, + fdflags: FdFlags, ) -> Result, 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); diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index e99dfe3a2b..78d5add518 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -519,11 +519,12 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { let table = self.table(); let file_entry: Ref = 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)))?;