sysfs: adds FS.Stat and companions in platform (#1140)

This centralizes filestat logic by making our own `Stat_t` similar to
`syscall.Stat_t`. This exposes utilities in the platform package and
adds a new function `FS.Stat` which avoids having to use `fs.File` to
get the same info. Doing so at the FS abstraction allows us to optimize
how it is implemented internally using portable means (e.g.
`os.StatFile`) or OS-specific means where necessary, e.g. in windows.

This also ensures `platform.OpenFile` returns syscall.Errno and
centralizes error checking with a new `require.EqualErrno` test.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-02-21 10:13:37 +08:00
committed by GitHub
parent 2587989f0a
commit 4ca0858e57
48 changed files with 967 additions and 679 deletions

View File

@@ -3,8 +3,6 @@ package gojs
import (
"syscall"
"testing"
"github.com/tetratelabs/wazero/internal/testing/require"
)
func TestToErrno(t *testing.T) {
@@ -103,8 +101,9 @@ func TestToErrno(t *testing.T) {
for _, tt := range tests {
tc := tt
t.Run(tc.name, func(t *testing.T) {
errno := ToErrno(tc.input)
require.Equal(t, tc.expected, errno)
if errno := ToErrno(tc.input); errno != tc.expected {
t.Fatalf("expected %#v but was %#v", tc.expected, errno)
}
})
}
}