Exposes sys.Stat_t as a portable alternative to syscall.Stat_t (#1567)

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-07-10 11:46:20 +08:00
committed by GitHub
parent d3f09bdcff
commit 6efcf25505
41 changed files with 707 additions and 261 deletions

26
sys/stat_windows.go Normal file
View File

@@ -0,0 +1,26 @@
//go:build (amd64 || arm64) && windows
package sys
import (
"io/fs"
"syscall"
)
const sysParseable = true
func statFromFileInfo(info fs.FileInfo) Stat_t {
if d, ok := info.Sys().(*syscall.Win32FileAttributeData); ok {
st := Stat_t{}
st.Ino = 0 // not in Win32FileAttributeData
st.Dev = 0 // not in Win32FileAttributeData
st.Mode = info.Mode()
st.Nlink = 1 // not in Win32FileAttributeData
st.Size = info.Size()
st.Atim = d.LastAccessTime.Nanoseconds()
st.Mtim = d.LastWriteTime.Nanoseconds()
st.Ctim = d.CreationTime.Nanoseconds()
return st
}
return defaultStatFromFileInfo(info)
}