Browse code

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 <estesp@linux.vnet.ibm.com>

Phil Estes authored on 2016/08/25 00:24:08
Showing 2 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,32 @@
0
+package system
1
+
2
+import (
3
+	"syscall"
4
+)
5
+
6
+// fromStatT creates a system.StatT type from a syscall.Stat_t type
7
+func fromStatT(s *syscall.Stat_t) (*StatT, error) {
8
+	return &StatT{size: s.Size,
9
+		mode: uint32(s.Mode),
10
+		uid:  s.Uid,
11
+		gid:  s.Gid,
12
+		rdev: uint64(s.Rdev),
13
+		mtim: s.Mtimespec}, nil
14
+}
15
+
16
+// FromStatT loads a system.StatT from a syscall.Stat_t.
17
+func FromStatT(s *syscall.Stat_t) (*StatT, error) {
18
+	return fromStatT(s)
19
+}
20
+
21
+// Stat takes a path to a file and returns
22
+// a system.StatT type pertaining to that file.
23
+//
24
+// Throws an error if the file does not exist
25
+func Stat(path string) (*StatT, error) {
26
+	s := &syscall.Stat_t{}
27
+	if err := syscall.Stat(path, s); err != nil {
28
+		return nil, err
29
+	}
30
+	return fromStatT(s)
31
+}
... ...
@@ -1,4 +1,4 @@
1
-// +build !linux,!windows,!freebsd,!solaris,!openbsd
1
+// +build !linux,!windows,!freebsd,!solaris,!openbsd,!darwin
2 2
 
3 3
 package system
4 4