diff --git a/internal/gojs/testdata/writefs/main.go b/internal/gojs/testdata/writefs/main.go index 95fe71ff89..0910e1068a 100644 --- a/internal/gojs/testdata/writefs/main.go +++ b/internal/gojs/testdata/writefs/main.go @@ -111,22 +111,20 @@ func Main() { } // Ensure the times translated properly. - if st, err := os.Stat(dir); err != nil { + st, err := os.Stat(dir) + if err != nil { + log.Panicln("unexpected error", err) + } + + df, err := os.Open(dir) + if err != nil { + log.Panicln("unexpected error", err) + } + atimeNsec, mtimeNsec, _, _, _, _, err := Stat(df, st) + if err != nil { log.Panicln("unexpected error", err) - } else { - atimeNsec, mtimeNsec, _ := statTimes(st) - fmt.Println("times:", atimeNsec, mtimeNsec) - - // statDeviceInode cannot be tested against real device values because - // the size of d.Dev (32-bit) in js is smaller than linux (64-bit). - // - // We can't test the real inode of dir, though we could /tmp as that - // file is visible on the host. However, we haven't yet implemented - // platform.StatDeviceInode on windows, so we couldn't run that test - // in CI. For now, this only tests there is no compilation problem or - // runtime panic. - _, _ = statDeviceInode(st) } + fmt.Println("times:", atimeNsec, mtimeNsec) // Test renaming a file, noting we can't verify error numbers as they // vary per operating system. diff --git a/internal/gojs/testdata/writefs/times.go b/internal/gojs/testdata/writefs/times.go index 9f472ab87e..025606fc62 100644 --- a/internal/gojs/testdata/writefs/times.go +++ b/internal/gojs/testdata/writefs/times.go @@ -3,15 +3,12 @@ package writefs import ( + "io/fs" "os" "github.com/tetratelabs/wazero/internal/platform" ) -func statTimes(t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64) { - return platform.StatTimes(t) // allow the file to compile and run outside JS -} - -func statDeviceInode(t os.FileInfo) (dev, inode uint64) { - return platform.StatDeviceInode(t) +func Stat(f fs.File, t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64, nlink, dev, inode uint64, err error) { + return platform.Stat(f, t) } diff --git a/internal/gojs/testdata/writefs/times_js.go b/internal/gojs/testdata/writefs/times_js.go index fe85241a20..f12b49cf03 100644 --- a/internal/gojs/testdata/writefs/times_js.go +++ b/internal/gojs/testdata/writefs/times_js.go @@ -1,16 +1,12 @@ package writefs import ( + "io/fs" "os" "syscall" ) -func statTimes(t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64) { +func Stat(_ fs.File, t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64, nlink, dev, inode uint64, err error) { d := t.Sys().(*syscall.Stat_t) - return d.Atime*1e9 + d.AtimeNsec, d.Mtime*1e9 + d.MtimeNsec, d.Ctime*1e9 + d.CtimeNsec -} - -func statDeviceInode(t os.FileInfo) (dev, inode uint64) { - d := t.Sys().(*syscall.Stat_t) - return uint64(d.Dev), uint64(d.Ino) + return d.Atime*1e9 + d.AtimeNsec, d.Mtime*1e9 + d.MtimeNsec, d.Ctime*1e9 + d.CtimeNsec, 0, uint64(d.Dev), uint64(d.Ino), nil } diff --git a/internal/platform/stat_bsd.go b/internal/platform/stat_bsd.go index d086d88cc0..4d065e6282 100644 --- a/internal/platform/stat_bsd.go +++ b/internal/platform/stat_bsd.go @@ -24,10 +24,3 @@ func stat(_ fs.File, t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64, nlin return atime.Sec*1e9 + atime.Nsec, mtime.Sec*1e9 + mtime.Nsec, ctime.Sec*1e9 + ctime.Nsec, uint64(d.Nlink), uint64(d.Dev), uint64(d.Ino), nil } - -func statDeviceInode(t os.FileInfo) (dev, inode uint64) { - d := t.Sys().(*syscall.Stat_t) - dev = uint64(d.Dev) - inode = d.Ino - return -} diff --git a/internal/platform/stat_linux.go b/internal/platform/stat_linux.go index 78240db9d8..ca6ee60f91 100644 --- a/internal/platform/stat_linux.go +++ b/internal/platform/stat_linux.go @@ -24,6 +24,5 @@ func stat(_ fs.File, t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64, nlin atime := d.Atim mtime := d.Mtim ctime := d.Ctim - return atime.Sec*1e9 + atime.Nsec, mtime.Sec*1e9 + mtime.Nsec, ctime.Sec*1e9 + ctime.Nsec, - uint64(d.Nlink), uint64(d.Dev), uint64(d.Ino), nil + return atime.Sec*1e9 + atime.Nsec, mtime.Sec*1e9 + mtime.Nsec, ctime.Sec*1e9 + ctime.Nsec, uint64(d.Nlink), uint64(d.Dev), uint64(d.Ino), nil } diff --git a/internal/platform/stat_unsupported.go b/internal/platform/stat_unsupported.go index ce05b3a7aa..29fd0b6c94 100644 --- a/internal/platform/stat_unsupported.go +++ b/internal/platform/stat_unsupported.go @@ -16,7 +16,3 @@ func stat(_ fs.File, t os.FileInfo) (atimeNsec, mtimeNsec, ctimeNsec int64, nlin atimeNsec, mtimeNsec, ctimeNsec = mtimes(t) return } - -func statDeviceInode(t os.FileInfo) (dev, inode uint64) { - return -}