Commit 608feace authored by Aaron Jacobs's avatar Aaron Jacobs

Add fusetesting.GetTimes.

This makes it easier to write integration tests for atime, ctime, and
mtime on both darwin and linux.
parents 895b8c41 5595fe09
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"fmt" "fmt"
"os" "os"
"reflect" "reflect"
"syscall"
"time" "time"
"github.com/jacobsa/oglematchers" "github.com/jacobsa/oglematchers"
...@@ -95,6 +96,12 @@ func birthtimeIsWithin( ...@@ -95,6 +96,12 @@ func birthtimeIsWithin(
return nil 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 // 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 // number. On platforms where there is no nlink field available, match all
// os.FileInfo values. // os.FileInfo values.
......
...@@ -36,3 +36,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) { ...@@ -36,3 +36,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) {
ok = true ok = true
return 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
}
...@@ -34,3 +34,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) { ...@@ -34,3 +34,10 @@ func extractNlink(sys interface{}) (nlink uint64, ok bool) {
ok = true ok = true
return 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
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment