wasmerio / wasmer

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
https://wasmer.io
MIT License
18.44k stars 789 forks source link

`filestat` should contain timestamps in nanoseconds, not seconds #4358

Closed yagehu closed 7 months ago

yagehu commented 8 months ago

Describe the bug

The filestat type returned by fd_filestat_get should contain timestamps in nanoseconds. However, currently Wasmer returns timestamps in seconds for directories, e.g. preopened directories.

wasmer 4.2.4 (1abcd2c 2023-12-16)
binary: wasmer-cli
commit-hash: 1abcd2cc63deeca13af6506add6029edaba4d657
commit-date: 2023-12-16
host: x86_64-unknown-linux-gnu
compiler: singlepass,cranelift
rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

Steps to reproduce

Compile this C snippet with wasi-sdk and run the binary with Wasmer.

clang wasmer-dir-time.c
wasmer run --dir . a.out
#include <unistd.h>
#include <sys/stat.h>
#include <stdio.h>

int main(void) {
  struct stat buf;

  int ret = fstat(4, &buf);
  if (ret != 0) {
    perror("fstat");
    return 1;
  }

  printf("atime %lld seconds", buf.st_atime);

  return 0;
}

Expected behavior

It should print a reasonable timestamp like:

atime 1702794075 seconds

Actual behavior

It prints a very small number:

atime 1 seconds

linear[bot] commented 8 months ago

RUN-23 `filestat` should contain timestamps in nanoseconds, not seconds