github.com/demonoid81/moby@v0.0.0-20200517203328-62dd8e17c460/pkg/system/stat_unix.go (about) 1 // +build !windows 2 3 package system // import "github.com/demonoid81/moby/pkg/system" 4 5 import ( 6 "os" 7 "syscall" 8 ) 9 10 // StatT type contains status of a file. It contains metadata 11 // like permission, owner, group, size, etc about a file. 12 type StatT struct { 13 mode uint32 14 uid uint32 15 gid uint32 16 rdev uint64 17 size int64 18 mtim syscall.Timespec 19 } 20 21 // Mode returns file's permission mode. 22 func (s StatT) Mode() uint32 { 23 return s.mode 24 } 25 26 // UID returns file's user id of owner. 27 func (s StatT) UID() uint32 { 28 return s.uid 29 } 30 31 // GID returns file's group id of owner. 32 func (s StatT) GID() uint32 { 33 return s.gid 34 } 35 36 // Rdev returns file's device ID (if it's special file). 37 func (s StatT) Rdev() uint64 { 38 return s.rdev 39 } 40 41 // Size returns file's size. 42 func (s StatT) Size() int64 { 43 return s.size 44 } 45 46 // Mtim returns file's last modification time. 47 func (s StatT) Mtim() syscall.Timespec { 48 return s.mtim 49 } 50 51 // IsDir reports whether s describes a directory. 52 func (s StatT) IsDir() bool { 53 return s.mode&syscall.S_IFDIR != 0 54 } 55 56 // Stat takes a path to a file and returns 57 // a system.StatT type pertaining to that file. 58 // 59 // Throws an error if the file does not exist 60 func Stat(path string) (*StatT, error) { 61 s := &syscall.Stat_t{} 62 if err := syscall.Stat(path, s); err != nil { 63 return nil, &os.PathError{Op: "Stat", Path: path, Err: err} 64 } 65 return fromStatT(s) 66 }