From d2f2d05fe0d4ebefb5033fb05224a5e919abd4fd Mon Sep 17 00:00:00 2001 From: Yage Hu Date: Sat, 16 Dec 2023 22:12:04 -0800 Subject: [PATCH] Use nanoseconds in `filestat` This commit fixes the `filestat` type which contains three timestamps. Per [WASI spec], they should be in nanoseconds. This is only a problem for directories. [WASI spec]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md#-timestamp-u64 Signed-off-by: Yage Hu --- lib/virtual-fs/src/mem_fs/filesystem.rs | 8 +++++--- lib/virtual-fs/src/mem_fs/mod.rs | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/virtual-fs/src/mem_fs/filesystem.rs b/lib/virtual-fs/src/mem_fs/filesystem.rs index 1e344b745e9..bf81d2093bd 100644 --- a/lib/virtual-fs/src/mem_fs/filesystem.rs +++ b/lib/virtual-fs/src/mem_fs/filesystem.rs @@ -1520,11 +1520,13 @@ mod test_filesystem { modified, len: 0 }) if - accessed == foo_metadata.accessed && - created == foo_metadata.created && + accessed <= foo_metadata.accessed && + created <= foo_metadata.created && modified > foo_metadata.modified ), - "the modified time of the parent is updated when file is renamed", + "the modified time of the parent is updated when file is renamed \n{:?}\n{:?}", + fs.metadata(path!("/")), + foo_metadata, ); } diff --git a/lib/virtual-fs/src/mem_fs/mod.rs b/lib/virtual-fs/src/mem_fs/mod.rs index 8d16dd784eb..77e85d9db26 100644 --- a/lib/virtual-fs/src/mem_fs/mod.rs +++ b/lib/virtual-fs/src/mem_fs/mod.rs @@ -142,7 +142,7 @@ fn time() -> u64 { std::time::SystemTime::now() .duration_since(std::time::SystemTime::UNIX_EPOCH) .unwrap() - .as_secs() + .as_nanos() as u64 } #[cfg(feature = "no-time")]