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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user