Skip to content

Commit 3f84e3e

Browse files
authored
Merge pull request #262 from thaJeztah/fix_freebsd
fs: implement Atime, Ctime, Mtime for bsd and darwin
2 parents 163414b + dbe44eb commit 3f84e3e

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

fs/stat_darwinbsd.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,36 @@
1919
package fs
2020

2121
import (
22+
"fmt"
23+
"io/fs"
2224
"syscall"
2325
"time"
2426
)
2527

28+
func Atime(st fs.FileInfo) (time.Time, error) {
29+
stSys, ok := st.Sys().(*syscall.Stat_t)
30+
if !ok {
31+
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
32+
}
33+
return time.Unix(stSys.Atimespec.Unix()), nil
34+
}
35+
36+
func Ctime(st fs.FileInfo) (time.Time, error) {
37+
stSys, ok := st.Sys().(*syscall.Stat_t)
38+
if !ok {
39+
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
40+
}
41+
return time.Unix(stSys.Ctimespec.Unix()), nil
42+
}
43+
44+
func Mtime(st fs.FileInfo) (time.Time, error) {
45+
stSys, ok := st.Sys().(*syscall.Stat_t)
46+
if !ok {
47+
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
48+
}
49+
return time.Unix(stSys.Mtimespec.Unix()), nil
50+
}
51+
2652
// StatAtime returns the access time from a stat struct
2753
func StatAtime(st *syscall.Stat_t) syscall.Timespec {
2854
return st.Atimespec

fs/stat_unix.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func Atime(st fs.FileInfo) (time.Time, error) {
3030
if !ok {
3131
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
3232
}
33-
return StatATimeAsTime(stSys), nil
33+
return time.Unix(stSys.Atim.Unix()), nil
3434
}
3535

3636
func Ctime(st fs.FileInfo) (time.Time, error) {

0 commit comments

Comments
 (0)