Browse Source

windows nightly can give us filestat info

pull/2577/head
Pat Hickey 4 years ago
parent
commit
4dd1836704
  1. 2
      Cargo.lock
  2. 5
      crates/wasi-c2/Cargo.toml
  3. 10
      crates/wasi-c2/build.rs
  4. 23
      crates/wasi-c2/src/file.rs

2
Cargo.lock

@ -2368,9 +2368,11 @@ version = "0.21.0"
dependencies = [
"anyhow",
"cap-std",
"cfg-if 1.0.0",
"fs-set-times",
"getrandom 0.2.0",
"libc",
"rustc_version",
"system-interface",
"thiserror",
"tracing",

5
crates/wasi-c2/Cargo.toml

@ -11,6 +11,7 @@ readme = "README.md"
edition = "2018"
include = ["src/**/*", "LICENSE", "build.rs"]
build = "build.rs"
publish = false
[dependencies]
anyhow = "1.0"
@ -22,6 +23,10 @@ tracing = "0.1.19"
system-interface = "0.2"
cap-std = "0.6"
fs-set-times = "0.2.1"
cfg-if = "1"
[build-dependencies]
rustc_version = "0.2"
[badges]
maintenance = { status = "actively-developed" }

10
crates/wasi-c2/build.rs

@ -5,4 +5,14 @@ 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");
}
_ => {}
}
}

23
crates/wasi-c2/src/file.rs

@ -1,4 +1,5 @@
use crate::Error;
use cfg_if::cfg_if;
use fs_set_times::SetTimes;
use std::ops::Deref;
use system_interface::fs::FileIoExt;
@ -193,14 +194,26 @@ impl WasiFile for cap_std::fs::File {
Ok(())
}
fn get_filestat(&self) -> Result<Filestat, Error> {
// XXX cap-std does not expose every part of filestat
#![allow(unreachable_code, unused_variables)]
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(windows)] && #[cfg_attr(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)
}
};
Ok(Filestat {
device_id: todo!(),
inode: todo!(),
device_id,
inode,
filetype: self.get_filetype()?,
nlink: todo!(),
nlink,
size: meta.len(),
atim: meta.accessed()?.into_std(),
mtim: meta.modified()?.into_std(),

Loading…
Cancel
Save