github.com/ssdev-go/moby@v17.12.1-ce-rc2+incompatible/pkg/system/stat_windows.go (about) 1 package system 2 3 import ( 4 "os" 5 "time" 6 ) 7 8 // StatT type contains status of a file. It contains metadata 9 // like permission, size, etc about a file. 10 type StatT struct { 11 mode os.FileMode 12 size int64 13 mtim time.Time 14 } 15 16 // Size returns file's size. 17 func (s StatT) Size() int64 { 18 return s.size 19 } 20 21 // Mode returns file's permission mode. 22 func (s StatT) Mode() os.FileMode { 23 return os.FileMode(s.mode) 24 } 25 26 // Mtim returns file's last modification time. 27 func (s StatT) Mtim() time.Time { 28 return time.Time(s.mtim) 29 } 30 31 // Stat takes a path to a file and returns 32 // a system.StatT type pertaining to that file. 33 // 34 // Throws an error if the file does not exist 35 func Stat(path string) (*StatT, error) { 36 fi, err := os.Stat(path) 37 if err != nil { 38 return nil, err 39 } 40 return fromStatT(&fi) 41 } 42 43 // fromStatT converts a os.FileInfo type to a system.StatT type 44 func fromStatT(fi *os.FileInfo) (*StatT, error) { 45 return &StatT{ 46 size: (*fi).Size(), 47 mode: (*fi).Mode(), 48 mtim: (*fi).ModTime()}, nil 49 }