1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
//go:build !darwin && !freebsd && !linux
// +build !darwin,!freebsd,!linux
package fs
import (
"os"
"time"
)
var zeroTime time.Time
func modKey(path string) (ModKey, error) {
info, err := os.Stat(path)
if err != nil {
return ModKey{}, err
}
// We can't detect changes if the file system zeros out the modification time
mtime := info.ModTime()
if mtime == zeroTime || mtime.Unix() == 0 {
return ModKey{}, modKeyUnusable
}
// Don't generate a modification key if the file is too new
if mtime.Add(modKeySafetyGap * time.Second).After(time.Now()) {
return ModKey{}, modKeyUnusable
}
return ModKey{
size: info.Size(),
mtime_sec: mtime.Unix(),
mode: uint32(info.Mode()),
}, nil
}
|