From f218b730935a254e69864c8de774000ae460e16a Mon Sep 17 00:00:00 2001 From: Will Scott Date: Mon, 26 Aug 2024 13:21:43 +0200 Subject: [PATCH] different struct names between darwin and linux --- file/file_darwin.go | 27 +++++++++++++++++++++++++++ file/file_unix.go | 6 +++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 file/file_darwin.go diff --git a/file/file_darwin.go b/file/file_darwin.go new file mode 100644 index 0000000..624573a --- /dev/null +++ b/file/file_darwin.go @@ -0,0 +1,27 @@ +//go:build darwin + +package file + +import ( + "os" + "syscall" + "time" + + "golang.org/x/sys/unix" +) + +func getOSFileInfo(info os.FileInfo) *FileInfo { + fi := &FileInfo{} + if s, ok := info.Sys().(*syscall.Stat_t); ok { + fi.Nlink = uint32(s.Nlink) + fi.UID = s.Uid + fi.GID = s.Gid + fi.Major = unix.Major(uint64(s.Rdev)) + fi.Minor = unix.Minor(uint64(s.Rdev)) + fi.Fileid = s.Ino + fi.Atime = time.Unix(s.Atimespec.Sec, s.Atimespec.Nsec) + fi.Ctime = time.Unix(s.Ctimespec.Sec, s.Ctimespec.Nsec) + return fi + } + return nil +} diff --git a/file/file_unix.go b/file/file_unix.go index edc86ce..220aedc 100644 --- a/file/file_unix.go +++ b/file/file_unix.go @@ -1,4 +1,4 @@ -//go:build darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris +//go:build dragonfly || freebsd || linux || nacl || netbsd || openbsd || solaris package file @@ -19,8 +19,8 @@ func getOSFileInfo(info os.FileInfo) *FileInfo { fi.Major = unix.Major(uint64(s.Rdev)) fi.Minor = unix.Minor(uint64(s.Rdev)) fi.Fileid = s.Ino - fi.Atime = time.Unix(s.Atimespec.Sec, s.Atimespec.Nsec) - fi.Ctime = time.Unix(s.Ctimespec.Sec, s.Ctimespec.Nsec) + fi.Atime = time.Unix(s.Atim.Sec, s.Atim.Nsec) + fi.Ctime = time.Unix(s.Ctim.Sec, s.Ctim.Nsec) return fi } return nil