diff --git a/Cargo.lock b/Cargo.lock index 019c8f7da5..6202b29490 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -216,7 +216,7 @@ dependencies = [ "ipnet", "libc", "once_cell", - "posish", + "posish 0.4.1", "winapi", "winx 0.20.0", ] @@ -928,7 +928,7 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a37c11eb7933093dd2a56c9c4d934a754b56e672fb8c2b46d50997dd2b4392d" dependencies = [ - "posish", + "posish 0.4.1", "winapi", ] @@ -1147,9 +1147,9 @@ checksum = "3576a87f2ba00f6f106fdfcd16db1d698d648a26ad8e0573cad8537c3c362d2a" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb" [[package]] name = "libfuzzer-sys" @@ -1512,6 +1512,19 @@ dependencies = [ "libc", ] +[[package]] +name = "posish" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06094810dcae89a17bd50335b044296eafc671346790c0a2fb1fb3adfce41bd6" +dependencies = [ + "bitflags", + "cfg-if 1.0.0", + "errno", + "itoa", + "libc", +] + [[package]] name = "ppv-lite86" version = "0.2.10" @@ -2048,12 +2061,12 @@ dependencies = [ [[package]] name = "system-interface" -version = "0.0.1-alpha.0" +version = "0.1.1-alpha.0" dependencies = [ "atty", - "posish", + "posish 0.5.2", "winapi", - "winx 0.20.0", + "winx 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2353,6 +2366,7 @@ version = "0.21.0" dependencies = [ "anyhow", "cap-std", + "fs-set-times", "getrandom 0.2.0", "libc", "system-interface", @@ -2908,6 +2922,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "winx" +version = "0.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2bcaffab7dbdc695c5d1e8adc37247111444c44f2df159f730d7ac85dbc27b5f" +dependencies = [ + "bitflags", + "cvt", + "winapi", +] + [[package]] name = "witx" version = "0.8.7" diff --git a/crates/wasi-c2/Cargo.toml b/crates/wasi-c2/Cargo.toml index a0e882b4cf..c6c0e54a80 100644 --- a/crates/wasi-c2/Cargo.toml +++ b/crates/wasi-c2/Cargo.toml @@ -19,8 +19,9 @@ libc = "0.2" getrandom = { version = "0.2.0", features = ["std"] } wiggle = { path = "../wiggle", default-features = false, version = "0.21.0" } tracing = "0.1.19" -system-interface = { path = "../../../system-interface" } -cap-std = "*" +system-interface = "0.2" +cap-std = "0.6" +fs-set-times = "0.2.1" [badges] maintenance = { status = "actively-developed" } diff --git a/crates/wasi-c2/src/file.rs b/crates/wasi-c2/src/file.rs index 9becd73a80..40c1b120a3 100644 --- a/crates/wasi-c2/src/file.rs +++ b/crates/wasi-c2/src/file.rs @@ -1,8 +1,9 @@ use crate::Error; +use fs_set_times::SetTimes; use std::ops::Deref; use system_interface::fs::FileIoExt; -pub trait WasiFile: FileIoExt { +pub trait WasiFile: FileIoExt + SetTimes { fn datasync(&self) -> Result<(), Error>; fn sync(&self) -> Result<(), Error>; fn get_filetype(&self) -> Result; @@ -10,13 +11,7 @@ pub trait WasiFile: FileIoExt { fn get_oflags(&self) -> Result; fn set_oflags(&self, _flags: OFlags) -> Result<(), Error>; fn get_filestat(&self) -> Result; - fn set_filestat_times( - &self, - _atim: Option, - _mtim: Option, - ) -> Result<(), Error>; fn set_filestat_size(&self, _size: u64) -> Result<(), Error>; - fn allocate(&self, _offset: u64, _len: u64) -> Result<(), Error>; } #[derive(Debug, Copy, Clone)] @@ -82,12 +77,6 @@ pub struct Filestat { ctim: std::time::SystemTime, } -#[derive(Debug, Copy, Clone)] -pub enum FilestatSetTime { - Now, - Absolute(std::time::SystemTime), -} - pub(crate) struct FileEntry { pub(crate) base_caps: FileCaps, pub(crate) inheriting_caps: FileCaps, @@ -218,29 +207,8 @@ impl WasiFile for cap_std::fs::File { ctim: meta.created()?.into_std(), }) } - fn set_filestat_times( - &self, - _atim: Option, - _mtim: Option, - ) -> Result<(), Error> { - // XXX cap-std does not expose a way to set accessed time or modified time - todo!() - } fn set_filestat_size(&self, size: u64) -> Result<(), Error> { self.set_len(size)?; Ok(()) } - fn allocate(&self, offset: u64, len: u64) -> Result<(), Error> { - let metadata = self.metadata()?; - let current_size = metadata.len(); - let wanted_size = offset.checked_add(len).ok_or(Error::TooBig)?; - // This check will be unnecessary when rust-lang/rust#63326 is fixed - if wanted_size > i64::max_value() as u64 { - return Err(Error::TooBig); - } - if wanted_size > current_size { - self.set_len(wanted_size)?; - } - Ok(()) - } } diff --git a/crates/wasi-c2/src/snapshots/preview_1.rs b/crates/wasi-c2/src/snapshots/preview_1.rs index 7bd1bc923e..d726a3dccb 100644 --- a/crates/wasi-c2/src/snapshots/preview_1.rs +++ b/crates/wasi-c2/src/snapshots/preview_1.rs @@ -1,9 +1,8 @@ #![allow(unused_variables)] use crate::dir::{DirCaps, DirEntry, TableDirExt}; -use crate::file::{ - FdFlags, FdStat, FileCaps, FileEntry, Filestat, FilestatSetTime, Filetype, OFlags, -}; +use crate::file::{FdFlags, FdStat, FileCaps, FileEntry, Filestat, Filetype, OFlags}; use crate::{Error, WasiCtx}; +use fs_set_times::SystemTimeSpec; use std::cell::RefMut; use std::convert::TryFrom; use std::io::{IoSlice, IoSliceMut}; @@ -265,25 +264,25 @@ impl<'a> wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx { return Err(Error::Inval); } let atim = if set_atim { - Some(FilestatSetTime::Absolute( + Some(SystemTimeSpec::Absolute( UNIX_EPOCH + Duration::from_nanos(atim), )) } else if set_atim_now { - Some(FilestatSetTime::Now) + Some(SystemTimeSpec::SymbolicNow) } else { None }; let mtim = if set_mtim { - Some(FilestatSetTime::Absolute( + Some(SystemTimeSpec::Absolute( UNIX_EPOCH + Duration::from_nanos(mtim), )) } else if set_mtim_now { - Some(FilestatSetTime::Now) + Some(SystemTimeSpec::SymbolicNow) } else { None }; - f.set_filestat_times(atim, mtim)?; + f.set_times(atim, mtim)?; Ok(()) }