switch to cap-fs-ext::MetadataExt

This commit is contained in:
Pat Hickey
2020-12-11 12:14:09 -08:00
parent 47f3a6bcb9
commit 73058658f4
4 changed files with 28 additions and 54 deletions

37
Cargo.lock generated
View File

@@ -206,26 +206,36 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
[[package]]
name = "cap-primitives"
version = "0.6.0"
name = "cap-fs-ext"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9069ed88e23a3fff56577518a238e6975920620cd5d00be8ca73aa46a96d5f5"
checksum = "724c2735539ad3ab51f04a0d84bca8c23398e558e810254a6996867fd6c7db81"
dependencies = [
"cap-primitives",
"cap-std",
]
[[package]]
name = "cap-primitives"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1b599a2508a28113d658c2f94f3d294d8023c3b34adb89204d7744ddbeb22a59"
dependencies = [
"errno",
"fs-set-times",
"ipnet",
"libc",
"once_cell",
"posish 0.4.1",
"posish 0.5.2",
"winapi",
"winx 0.20.0",
"winx 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "cap-std"
version = "0.6.0"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eacf34fea6948253011b8771b7ae6258a2ae15c7ba38e78b7dd60a785af354d2"
checksum = "0760daa4e6270daa9c5c6ad133108fb77edfe023a019c392d98dd769defa42d5"
dependencies = [
"cap-primitives",
]
@@ -2367,12 +2377,12 @@ name = "wasi-c2"
version = "0.21.0"
dependencies = [
"anyhow",
"cap-fs-ext",
"cap-std",
"cfg-if 1.0.0",
"fs-set-times",
"getrandom 0.2.0",
"libc",
"rustc_version",
"system-interface",
"thiserror",
"tracing",
@@ -2906,17 +2916,6 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "winx"
version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b25e4ae373f2f2f7f5f187974ed315719ce74160859027c80deb1f68b3c0c966"
dependencies = [
"bitflags",
"cvt",
"winapi",
]
[[package]]
name = "winx"
version = "0.21.0"

View File

@@ -21,13 +21,11 @@ getrandom = { version = "0.2.0", features = ["std"] }
wiggle = { path = "../wiggle", default-features = false, version = "0.21.0" }
tracing = "0.1.19"
system-interface = "0.2"
cap-std = "0.6"
cap-std = "0.7"
cap-fs-ext = "0.7"
fs-set-times = "0.2.1"
cfg-if = "1"
[build-dependencies]
rustc_version = "0.2"
[badges]
maintenance = { status = "actively-developed" }

View File

@@ -5,14 +5,4 @@ fn main() {
let wasi = cwd.join("..").join("wasi-common").join("WASI");
println!("cargo:wasi={}", wasi.display());
println!("cargo:rustc-env=WASI_ROOT={}", wasi.display());
match rustc_version::version_meta()
.expect("query rustc release channel")
.channel
{
rustc_version::Channel::Nightly => {
println!("cargo:rustc-cfg=nightly");
}
_ => {}
}
}

View File

@@ -177,14 +177,16 @@ impl WasiFile for cap_std::fs::File {
if meta.is_file() {
Ok(Filetype::RegularFile)
} else {
Err(Error::Badf) // XXX idk what to do here
todo!("get_filetype doesnt know how to handle case when not a file");
}
}
fn get_fdflags(&self) -> Result<FdFlags, Error> {
// XXX cap-std doesnt expose append, dsync, nonblock, rsync, sync
todo!()
todo!("get_fdflags is not implemented")
}
fn get_oflags(&self) -> Result<OFlags, Error> {
#![allow(unreachable_code, unused_variables)]
todo!("get_oflags implementation is incomplete");
// XXX what if it was opened append, async, nonblock...
let perms = self.metadata()?.permissions();
if perms.readonly() {
@@ -210,27 +212,12 @@ impl WasiFile for cap_std::fs::File {
}
fn get_filestat(&self) -> Result<Filestat, Error> {
let meta = self.metadata()?;
let (device_id, inode, nlink) = {
cfg_if! {
if #[cfg(unix)] {
use std::os::unix::fs::MetadataExt;
(meta.dev(), meta.ino(), meta.nlink())
} else if #[cfg(all(windows, feature = "nightly"))] {
use std::os::windows::fs::MetadataExt;
( meta.volume_serial_number().unwrap_or(-1),
meta.file_index().unwrap_or(-1),
meta.number_of_links().unwrap_or(0),
)
} else {
(-1, -1, 0)
}
}
};
use cap_fs_ext::MetadataExt;
Ok(Filestat {
device_id,
inode,
device_id: meta.dev(),
inode: meta.ino(),
filetype: self.get_filetype()?,
nlink,
nlink: meta.nlink(),
size: meta.len(),
atim: meta.accessed()?.into_std(),
mtim: meta.modified()?.into_std(),