Skip to content

Commit

Permalink
leftover
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
  • Loading branch information
mathetake committed Feb 16, 2023
1 parent 4736681 commit 694ed10
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 40 deletions.
26 changes: 12 additions & 14 deletions internal/gojs/testdata/writefs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 3 additions & 6 deletions internal/gojs/testdata/writefs/times.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
10 changes: 3 additions & 7 deletions internal/gojs/testdata/writefs/times_js.go
Original file line number Diff line number Diff line change
@@ -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
}
7 changes: 0 additions & 7 deletions internal/platform/stat_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 1 addition & 2 deletions internal/platform/stat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 0 additions & 4 deletions internal/platform/stat_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 694ed10

Please sign in to comment.