gojs: implements lstat This implements platform.Lstat and uses it in GOOS=js. Notably, directory listings need to run lstat on their entries to get the correct inodes back. In GOOS=js, directories are a fan-out of names, then lstat. This also fixes stat for inodes on directories. We were missing a test so we didn't know it was broken on windows. The approach used now is reliable on go 1.20, and we should suggest anyone using windows to compile with go 1.20. Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
51 lines
1.1 KiB
Go
51 lines
1.1 KiB
Go
//go:build (amd64 || arm64 || riscv64) && 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 platform
|
|
|
|
import (
|
|
"io/fs"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
func lstat(path string, st *Stat_t) (err error) {
|
|
var t fs.FileInfo
|
|
if t, err = os.Lstat(path); err == nil {
|
|
fillStatFromFileInfo(st, t)
|
|
}
|
|
return
|
|
}
|
|
|
|
func stat(path string, st *Stat_t) (err error) {
|
|
var t fs.FileInfo
|
|
if t, err = os.Stat(path); err == nil {
|
|
fillStatFromFileInfo(st, t)
|
|
}
|
|
return
|
|
}
|
|
|
|
func statFile(f fs.File, st *Stat_t) error {
|
|
return defaultStatFile(f, st)
|
|
}
|
|
|
|
func fillStatFromFileInfo(st *Stat_t, t fs.FileInfo) {
|
|
if d, ok := t.Sys().(*syscall.Stat_t); ok {
|
|
st.Ino = uint64(d.Ino)
|
|
st.Dev = uint64(d.Dev)
|
|
st.Mode = t.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
|
|
} else {
|
|
fillStatFromDefaultFileInfo(st, t)
|
|
}
|
|
}
|