Debian Codegraph @

lib/ftime_bsd.go

raw
1 // +build freebsd darwin netbsd
2
3 package lib
4
5 import (
6 "time"
7
8 "golang.org/x/sys/unix"
9 )
10
11 // FileTime contains the changed, modified, and accessed timestamps
12 // for a file.
13 type FileTime struct {
14 Changed time.Time
15 Modified time.Time
16 Accessed time.Time
17 }
18
19 func timeSpecToTime(ts unix.Timespec) time.Time {
20 return time.Unix(ts.Sec, ts.Nsec)
21 }
22
23 // LoadFileTime returns a FileTime associated with the file.
24 func LoadFileTime(path string) (FileTime, error) {
25 var ft = FileTime{}
26 var st = unix.Stat_t{}
27
28 err := unix.Stat(path, &st)
29 if err != nil {
30 return ft, err
31 }
32
33 ft.Changed = timeSpecToTime(st.Ctimespec)
34 ft.Modified = timeSpecToTime(st.Mtimespec)
35 ft.Accessed = timeSpecToTime(st.Atimespec)
36 return ft, nil
37 }