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

@@ -100,17 +100,16 @@ func WriteTestFiles(tmpDir string) (err error) {
}
// os.Stat uses GetFileInformationByHandle internally.
stat, err := os.Stat(path)
if err != nil {
var stat platform.Stat_t
if err = platform.Stat(path, &stat); err != nil {
return err
}
if stat.ModTime() == info.ModTime() {
if stat.Mtim == info.ModTime().UnixNano() {
return nil // synced!
}
// Otherwise, we need to sync the timestamps.
atimeNsec, mtimeNsec, _ := platform.StatTimes(stat)
return os.Chtimes(path, time.Unix(0, atimeNsec), time.Unix(0, mtimeNsec))
return os.Chtimes(path, time.Unix(0, stat.Atim), time.Unix(0, stat.Mtim))
})
}
return