mirror of
https://github.com/wazero/wazero
synced 2026-06-21 14:12:37 +00:00
Streamline build tags: remove tinygo, cgo (#2446)
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
//go:build amd64 && !tinygo
|
||||
|
||||
package wazevo
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build arm64 && !tinygo
|
||||
|
||||
package wazevo
|
||||
|
||||
import _ "unsafe"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
//go:build (!arm64 && !amd64) || tinygo
|
||||
//go:build !(arm64 || amd64)
|
||||
|
||||
package wazevo
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (linux || darwin || freebsd || netbsd || dragonfly || solaris) && !tinygo
|
||||
//go:build linux || darwin || freebsd || netbsd || dragonfly || solaris
|
||||
|
||||
package platform
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !(linux || darwin || freebsd || netbsd || dragonfly || solaris || windows) || tinygo
|
||||
//go:build !(linux || darwin || freebsd || netbsd || dragonfly || solaris || windows)
|
||||
|
||||
package platform
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (freebsd || netbsd || dragonfly) && !tinygo
|
||||
//go:build freebsd || netbsd || dragonfly
|
||||
|
||||
package platform
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (linux || darwin) && !tinygo
|
||||
//go:build linux || darwin
|
||||
|
||||
package platform
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build solaris && !tinygo
|
||||
//go:build solaris
|
||||
|
||||
package platform
|
||||
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build !cgo && !windows
|
||||
|
||||
package platform
|
||||
|
||||
func nanotime() int64 {
|
||||
return nanotimePortable()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build cgo && !windows
|
||||
//go:build !windows
|
||||
|
||||
package platform
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !plan9 && !js && !tinygo
|
||||
//go:build !(plan9 || js)
|
||||
|
||||
package sock
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build plan9 || js || tinygo
|
||||
//go:build plan9 || js
|
||||
|
||||
package sock
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build linux && !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
//go:build tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
func datasync(f *os.File) sys.Errno {
|
||||
return sys.ENOSYS
|
||||
}
|
||||
+43
-5
@@ -3,6 +3,7 @@ package sysfs
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/platform"
|
||||
@@ -63,6 +64,48 @@ func (d *dirFS) Mkdir(path string, perm fs.FileMode) (errno experimentalsys.Errn
|
||||
return
|
||||
}
|
||||
|
||||
// Chmod implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
|
||||
err := os.Chmod(d.join(path), perm)
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
|
||||
// Rename implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
|
||||
from, to = d.join(from), d.join(to)
|
||||
return rename(from, to)
|
||||
}
|
||||
|
||||
// Rmdir implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Rmdir(path string) experimentalsys.Errno {
|
||||
return rmdir(d.join(path))
|
||||
}
|
||||
|
||||
// Unlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
|
||||
return unlink(d.join(path))
|
||||
}
|
||||
|
||||
// Link implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
|
||||
err := os.Link(d.join(oldName), d.join(newName))
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
|
||||
// Symlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
|
||||
// Creating a symlink with an absolute path string fails with a "not permitted" error.
|
||||
// https://github.com/WebAssembly/wasi-filesystem/blob/v0.2.0/path-resolution.md#symlinks
|
||||
if path.IsAbs(oldName) {
|
||||
return experimentalsys.EPERM
|
||||
}
|
||||
// Note: do not resolve `oldName` relative to this dirFS. The link result is always resolved
|
||||
// when dereference the `link` on its usage (e.g. readlink, read, etc).
|
||||
// https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
|
||||
err := os.Symlink(oldName, d.join(link))
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
|
||||
// Readlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Readlink(path string) (string, experimentalsys.Errno) {
|
||||
// Note: do not use syscall.Readlink as that causes race on Windows.
|
||||
@@ -74,11 +117,6 @@ func (d *dirFS) Readlink(path string) (string, experimentalsys.Errno) {
|
||||
return platform.ToPosixPath(dst), 0
|
||||
}
|
||||
|
||||
// Rmdir implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Rmdir(path string) experimentalsys.Errno {
|
||||
return rmdir(d.join(path))
|
||||
}
|
||||
|
||||
// Utimens implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Utimens(path string, atim, mtim int64) experimentalsys.Errno {
|
||||
return utimens(d.join(path), atim, mtim)
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
// Link implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
|
||||
err := os.Link(d.join(oldName), d.join(newName))
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
|
||||
// Unlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
|
||||
return unlink(d.join(path))
|
||||
}
|
||||
|
||||
// Rename implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
|
||||
from, to = d.join(from), d.join(to)
|
||||
return rename(from, to)
|
||||
}
|
||||
|
||||
// Chmod implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
|
||||
err := os.Chmod(d.join(path), perm)
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
|
||||
// Symlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
|
||||
// Creating a symlink with an absolute path string fails with a "not permitted" error.
|
||||
// https://github.com/WebAssembly/wasi-filesystem/blob/v0.2.0/path-resolution.md#symlinks
|
||||
if path.IsAbs(oldName) {
|
||||
return experimentalsys.EPERM
|
||||
}
|
||||
// Note: do not resolve `oldName` relative to this dirFS. The link result is always resolved
|
||||
// when dereference the `link` on its usage (e.g. readlink, read, etc).
|
||||
// https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
|
||||
err := os.Symlink(oldName, d.join(link))
|
||||
return experimentalsys.UnwrapOSError(err)
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
//go:build tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
// Link implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Unlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Rename implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Chmod implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
|
||||
// Symlink implements the same method as documented on sys.FS
|
||||
func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
|
||||
return experimentalsys.ENOSYS
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build unix && !tinygo
|
||||
//go:build unix
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !(unix || windows) || tinygo
|
||||
//go:build !(unix || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (linux || darwin) && !tinygo
|
||||
//go:build linux || darwin
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/internal/platform"
|
||||
"github.com/tetratelabs/wazero/internal/testing/require"
|
||||
)
|
||||
@@ -26,11 +25,11 @@ func TestUtimens(t *testing.T) {
|
||||
func TestFileUtimens(t *testing.T) {
|
||||
testUtimens(t, true)
|
||||
|
||||
testEBADFIfFileClosed(t, func(f experimentalsys.File) experimentalsys.Errno {
|
||||
return f.Utimens(experimentalsys.UTIME_OMIT, experimentalsys.UTIME_OMIT)
|
||||
testEBADFIfFileClosed(t, func(f sys.File) sys.Errno {
|
||||
return f.Utimens(sys.UTIME_OMIT, sys.UTIME_OMIT)
|
||||
})
|
||||
testEBADFIfDirClosed(t, func(d experimentalsys.File) experimentalsys.Errno {
|
||||
return d.Utimens(experimentalsys.UTIME_OMIT, experimentalsys.UTIME_OMIT)
|
||||
testEBADFIfDirClosed(t, func(d sys.File) sys.Errno {
|
||||
return d.Utimens(sys.UTIME_OMIT, sys.UTIME_OMIT)
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (!windows && !linux && !darwin) || tinygo
|
||||
//go:build !(windows || linux || darwin)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
//go:build tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
|
||||
func inoFromFileInfo(_ string, info fs.FileInfo) (sys.Inode, experimentalsys.Errno) {
|
||||
return 0, experimentalsys.ENOTSUP
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
//go:build unix
|
||||
|
||||
package sysfs
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !(unix || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
//go:build unix
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build plan9 || tinygo
|
||||
//go:build !(unix || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build freebsd || dragonfly
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
@@ -1,31 +0,0 @@
|
||||
//go:build illumos || solaris
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
const supportedSyscallOflag = sys.O_DIRECTORY | sys.O_DSYNC | sys.O_NOFOLLOW | sys.O_NONBLOCK | sys.O_RSYNC
|
||||
|
||||
func withSyscallOflag(oflag sys.Oflag, flag int) int {
|
||||
if oflag&sys.O_DIRECTORY != 0 {
|
||||
// See https://github.com/illumos/illumos-gate/blob/edd580643f2cf1434e252cd7779e83182ea84945/usr/src/uts/common/sys/fcntl.h#L90
|
||||
flag |= 0x1000000
|
||||
}
|
||||
if oflag&sys.O_DSYNC != 0 {
|
||||
flag |= syscall.O_DSYNC
|
||||
}
|
||||
if oflag&sys.O_NOFOLLOW != 0 {
|
||||
flag |= syscall.O_NOFOLLOW
|
||||
}
|
||||
if oflag&sys.O_NONBLOCK != 0 {
|
||||
flag |= syscall.O_NONBLOCK
|
||||
}
|
||||
if oflag&sys.O_RSYNC != 0 {
|
||||
flag |= syscall.O_RSYNC
|
||||
}
|
||||
return flag
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !tinygo
|
||||
//go:build linux || netbsd || openbsd || solaris
|
||||
|
||||
package sysfs
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
//go:build tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
const supportedSyscallOflag = sys.Oflag(0)
|
||||
|
||||
func withSyscallOflag(oflag sys.Oflag, flag int) int {
|
||||
// O_DIRECTORY not defined
|
||||
// O_DSYNC not defined
|
||||
// O_NOFOLLOW not defined
|
||||
// O_NONBLOCK not defined
|
||||
// O_RSYNC not defined
|
||||
return flag
|
||||
}
|
||||
|
||||
func openFile(path string, oflag sys.Oflag, perm fs.FileMode) (*os.File, sys.Errno) {
|
||||
return nil, sys.ENOSYS
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !tinygo
|
||||
//go:build !windows
|
||||
|
||||
package sysfs
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
//go:build !darwin && !linux && !windows && !illumos && !solaris && !freebsd
|
||||
//go:build !(freebsd || dragonfly || darwin || linux || netbsd || openbsd || solaris || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
import "github.com/tetratelabs/wazero/experimental/sys"
|
||||
|
||||
const supportedSyscallOflag = sys.Oflag(0)
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build windows || (linux && !tinygo) || darwin
|
||||
//go:build windows || linux || darwin
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build !tinygo
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !(linux || darwin || windows) || tinygo
|
||||
//go:build !(linux || darwin || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ func TestPoll_Windows(t *testing.T) {
|
||||
|
||||
t.Run("poll should return immediately when duration is zero (no data)", func(t *testing.T) {
|
||||
r, w, err := os.Pipe()
|
||||
require.NoError(t, err)
|
||||
defer r.Close()
|
||||
defer w.Close()
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
//go:build unix
|
||||
|
||||
package sysfs
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
//go:build !(unix || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (linux || darwin || windows) && !tinygo
|
||||
//go:build linux || darwin || windows
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (linux || darwin) && !tinygo
|
||||
//go:build linux || darwin
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (!linux && !darwin && !windows) || tinygo
|
||||
//go:build !(linux || darwin || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
//go:build (amd64 || arm64) && (darwin || freebsd)
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
|
||||
experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
|
||||
"github.com/tetratelabs/wazero/sys"
|
||||
)
|
||||
|
||||
// dirNlinkIncludesDot is true because even though os.File filters out dot
|
||||
// entries, the underlying syscall.Stat includes them.
|
||||
//
|
||||
// Note: this is only used in tests
|
||||
const dirNlinkIncludesDot = true
|
||||
|
||||
func lstat(path string) (sys.Stat_t, experimentalsys.Errno) {
|
||||
if info, err := os.Lstat(path); err != nil {
|
||||
return sys.Stat_t{}, experimentalsys.UnwrapOSError(err)
|
||||
} else {
|
||||
return sys.NewStat_t(info), 0
|
||||
}
|
||||
}
|
||||
|
||||
func stat(path string) (sys.Stat_t, experimentalsys.Errno) {
|
||||
if info, err := os.Stat(path); err != nil {
|
||||
return sys.Stat_t{}, experimentalsys.UnwrapOSError(err)
|
||||
} else {
|
||||
return sys.NewStat_t(info), 0
|
||||
}
|
||||
}
|
||||
|
||||
func statFile(f fs.File) (sys.Stat_t, experimentalsys.Errno) {
|
||||
return defaultStatFile(f)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (amd64 || arm64 || ppc64le || riscv64 || s390x) && linux
|
||||
//go:build linux || darwin || freebsd || netbsd || openbsd || dragonfly || solaris
|
||||
|
||||
// Note: This expression is not the same as compiler support, even if it looks
|
||||
// similar. Platform functions here are used in interpreter mode as well.
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (!((amd64 || arm64 || ppc64le || riscv64 || s390x) && linux) && !((amd64 || arm64) && (darwin || freebsd)) && !((amd64 || arm64) && windows)) || js
|
||||
//go:build !(linux || darwin || freebsd || netbsd || openbsd || dragonfly || solaris || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build (amd64 || arm64) && windows
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build !windows && !plan9 && !tinygo
|
||||
//go:build unix
|
||||
|
||||
package sysfs
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
//go:build !(unix || windows)
|
||||
|
||||
package sysfs
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"os"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental/sys"
|
||||
)
|
||||
|
||||
func unlink(name string) sys.Errno {
|
||||
err := syscall.Remove(name)
|
||||
err := os.Remove(name)
|
||||
return sys.UnwrapOSError(err)
|
||||
}
|
||||
+6
-6
@@ -1,4 +1,4 @@
|
||||
//go:build (amd64 || arm64) && (darwin || freebsd)
|
||||
//go:build darwin || freebsd || netbsd
|
||||
|
||||
package sys
|
||||
|
||||
@@ -13,16 +13,16 @@ func statFromFileInfo(info fs.FileInfo) Stat_t {
|
||||
if d, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
st := Stat_t{}
|
||||
st.Dev = uint64(d.Dev)
|
||||
st.Ino = d.Ino
|
||||
st.Ino = Inode(d.Ino)
|
||||
st.Mode = info.Mode()
|
||||
st.Nlink = uint64(d.Nlink)
|
||||
st.Size = d.Size
|
||||
st.Size = int64(d.Size)
|
||||
atime := d.Atimespec
|
||||
st.Atim = atime.Sec*1e9 + atime.Nsec
|
||||
st.Atim = EpochNanos(atime.Sec)*1e9 + EpochNanos(atime.Nsec)
|
||||
mtime := d.Mtimespec
|
||||
st.Mtim = mtime.Sec*1e9 + mtime.Nsec
|
||||
st.Mtim = EpochNanos(mtime.Sec)*1e9 + EpochNanos(mtime.Nsec)
|
||||
ctime := d.Ctimespec
|
||||
st.Ctim = ctime.Sec*1e9 + ctime.Nsec
|
||||
st.Ctim = EpochNanos(ctime.Sec)*1e9 + EpochNanos(ctime.Nsec)
|
||||
return st
|
||||
}
|
||||
return defaultStatFromFileInfo(info)
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
//go:build (amd64 || arm64 || ppc64le || riscv64 || s390x) && linux
|
||||
|
||||
// Note: This expression is not the same as compiler support, even if it looks
|
||||
// similar. Platform functions here are used in interpreter mode as well.
|
||||
|
||||
package sys
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const sysParseable = true
|
||||
|
||||
func statFromFileInfo(info fs.FileInfo) Stat_t {
|
||||
if d, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
st := Stat_t{}
|
||||
st.Dev = uint64(d.Dev)
|
||||
st.Ino = uint64(d.Ino)
|
||||
st.Mode = info.Mode()
|
||||
st.Nlink = uint64(d.Nlink)
|
||||
st.Size = d.Size
|
||||
atime := d.Atim
|
||||
st.Atim = atime.Sec*1e9 + atime.Nsec
|
||||
mtime := d.Mtim
|
||||
st.Mtim = mtime.Sec*1e9 + mtime.Nsec
|
||||
ctime := d.Ctim
|
||||
st.Ctim = ctime.Sec*1e9 + ctime.Nsec
|
||||
return st
|
||||
}
|
||||
return defaultStatFromFileInfo(info)
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
//go:build linux || openbsd || dragonfly || solaris
|
||||
|
||||
package sys
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
const sysParseable = true
|
||||
|
||||
func statFromFileInfo(info fs.FileInfo) Stat_t {
|
||||
if d, ok := info.Sys().(*syscall.Stat_t); ok {
|
||||
st := Stat_t{}
|
||||
st.Dev = uint64(d.Dev)
|
||||
st.Ino = Inode(d.Ino)
|
||||
st.Mode = info.Mode()
|
||||
st.Nlink = uint64(d.Nlink)
|
||||
st.Size = int64(d.Size)
|
||||
atime := d.Atim
|
||||
st.Atim = EpochNanos(atime.Sec)*1e9 + EpochNanos(atime.Nsec)
|
||||
mtime := d.Mtim
|
||||
st.Mtim = EpochNanos(mtime.Sec)*1e9 + EpochNanos(mtime.Nsec)
|
||||
ctime := d.Ctim
|
||||
st.Ctim = EpochNanos(ctime.Sec)*1e9 + EpochNanos(ctime.Nsec)
|
||||
return st
|
||||
}
|
||||
return defaultStatFromFileInfo(info)
|
||||
}
|
||||
+7
-1
@@ -116,8 +116,14 @@ func Test_NewStat_t(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
tc := tt
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
switch runtime.GOOS {
|
||||
case "linux", "darwin", "freebsd", "netbsd", "openbsd", "dragonfly", "solaris", "illumos":
|
||||
break
|
||||
default:
|
||||
tc.expectDevIno = false
|
||||
}
|
||||
st := sys.NewStat_t(tc.info)
|
||||
if tc.expectDevIno && (runtime.GOOS == "linux" || runtime.GOOS == "darwin" || runtime.GOOS == "freebsd") {
|
||||
if tc.expectDevIno {
|
||||
require.NotEqual(t, uint64(0), st.Dev)
|
||||
require.NotEqual(t, uint64(0), st.Ino)
|
||||
} else {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//go:build (!((amd64 || arm64 || ppc64le || riscv64 || s390x) && linux) && !((amd64 || arm64) && (darwin || freebsd)) && !((amd64 || arm64) && windows)) || js
|
||||
//go:build !(linux || darwin || freebsd || netbsd || openbsd || dragonfly || solaris || windows)
|
||||
|
||||
package sys
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build (amd64 || arm64) && windows
|
||||
|
||||
package sys
|
||||
|
||||
import (
|
||||
|
||||
Reference in New Issue
Block a user