From 76a416ac37e5bd184990c93ed19aa6fa544b7b03 Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Wed, 24 Aug 2016 11:24:08 -0400 Subject: [PATCH] Add system.Stat support for darwin/macOS darwin had unbuildable support for our system.Stat() implementation. Docker-DCO-1.1-Signed-off-by: Phil Estes --- pkg/system/stat_darwin.go | 32 ++++++++++++++++++++++++++++++++ pkg/system/stat_unsupported.go | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 pkg/system/stat_darwin.go diff --git a/pkg/system/stat_darwin.go b/pkg/system/stat_darwin.go new file mode 100644 index 0000000000..f0742f59e5 --- /dev/null +++ b/pkg/system/stat_darwin.go @@ -0,0 +1,32 @@ +package system + +import ( + "syscall" +) + +// fromStatT creates a system.StatT type from a syscall.Stat_t type +func fromStatT(s *syscall.Stat_t) (*StatT, error) { + return &StatT{size: s.Size, + mode: uint32(s.Mode), + uid: s.Uid, + gid: s.Gid, + rdev: uint64(s.Rdev), + mtim: s.Mtimespec}, nil +} + +// FromStatT loads a system.StatT from a syscall.Stat_t. +func FromStatT(s *syscall.Stat_t) (*StatT, error) { + return fromStatT(s) +} + +// Stat takes a path to a file and returns +// a system.StatT type pertaining to that file. +// +// Throws an error if the file does not exist +func Stat(path string) (*StatT, error) { + s := &syscall.Stat_t{} + if err := syscall.Stat(path, s); err != nil { + return nil, err + } + return fromStatT(s) +} diff --git a/pkg/system/stat_unsupported.go b/pkg/system/stat_unsupported.go index f53e9de4d1..5d85f523cf 100644 --- a/pkg/system/stat_unsupported.go +++ b/pkg/system/stat_unsupported.go @@ -1,4 +1,4 @@ -// +build !linux,!windows,!freebsd,!solaris,!openbsd +// +build !linux,!windows,!freebsd,!solaris,!openbsd,!darwin package system