Skip to content

Commit

Permalink
Merge pull request #262 from thaJeztah/fix_freebsd
Browse files Browse the repository at this point in the history
fs: implement Atime, Ctime, Mtime for bsd and darwin
  • Loading branch information
AkihiroSuda authored Oct 30, 2024
2 parents 163414b + dbe44eb commit 3f84e3e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions fs/stat_darwinbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,36 @@
package fs

import (
"fmt"
"io/fs"
"syscall"
"time"
)

func Atime(st fs.FileInfo) (time.Time, error) {
stSys, ok := st.Sys().(*syscall.Stat_t)
if !ok {
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
}
return time.Unix(stSys.Atimespec.Unix()), nil
}

func Ctime(st fs.FileInfo) (time.Time, error) {
stSys, ok := st.Sys().(*syscall.Stat_t)
if !ok {
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
}
return time.Unix(stSys.Ctimespec.Unix()), nil
}

func Mtime(st fs.FileInfo) (time.Time, error) {
stSys, ok := st.Sys().(*syscall.Stat_t)
if !ok {
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
}
return time.Unix(stSys.Mtimespec.Unix()), nil
}

// StatAtime returns the access time from a stat struct
func StatAtime(st *syscall.Stat_t) syscall.Timespec {
return st.Atimespec
Expand Down
2 changes: 1 addition & 1 deletion fs/stat_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func Atime(st fs.FileInfo) (time.Time, error) {
if !ok {
return time.Time{}, fmt.Errorf("expected st.Sys() to be *syscall.Stat_t, got %T", st.Sys())
}
return StatATimeAsTime(stSys), nil
return time.Unix(stSys.Atim.Unix()), nil
}

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

0 comments on commit 3f84e3e

Please sign in to comment.