diff --git a/fusetesting/stat.go b/fusetesting/stat.go index 0c647eb..ace2dfb 100644 --- a/fusetesting/stat.go +++ b/fusetesting/stat.go @@ -18,6 +18,7 @@ import ( "fmt" "os" "reflect" + "syscall" "time" "github.com/jacobsa/oglematchers" @@ -95,6 +96,12 @@ func birthtimeIsWithin( return nil } +// Extract time information from the supplied file info. Panic on platforms +// where this is not possible. +func GetTimes(fi os.FileInfo) (atime, ctime, mtime time.Time) { + return getTimes(fi.Sys().(*syscall.Stat_t)) +} + // Match os.FileInfo values that specify a number of links equal to the given // number. On platforms where there is no nlink field available, match all // os.FileInfo values. diff --git a/fusetesting/stat_darwin.go b/fusetesting/stat_darwin.go index 9b4ebf5..348311a 100644 --- a/fusetesting/stat_darwin.go +++ b/fusetesting/stat_darwin.go @@ -36,3 +36,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) { ok = true return } + +func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) { + atime = time.Unix(stat.Atimespec.Unix()) + ctime = time.Unix(stat.Ctimespec.Unix()) + mtime = time.Unix(stat.Mtimespec.Unix()) + return +} diff --git a/fusetesting/stat_linux.go b/fusetesting/stat_linux.go index eec3568..40e7373 100644 --- a/fusetesting/stat_linux.go +++ b/fusetesting/stat_linux.go @@ -34,3 +34,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) { ok = true return } + +func getTimes(stat *syscall.Stat_t) (atime, ctime, mtime time.Time) { + atime = time.Unix(stat.Atim.Unix()) + ctime = time.Unix(stat.Ctim.Unix()) + mtime = time.Unix(stat.Mtim.Unix()) + return +}