github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/client/logging/stat_darwin.go (about) 1 package logging 2 3 import ( 4 "fmt" 5 "os" 6 "syscall" //nolint:depguard // We specifically need "syscall.Stat_t" rather than "unix.Stat_t" for fs.File.Sys(). 7 "time" 8 9 "github.com/telepresenceio/telepresence/v2/pkg/dos" 10 ) 11 12 type fileInfo struct { 13 *syscall.Stat_t 14 } 15 16 func osFStat(file dos.File) (SysInfo, error) { 17 stat, err := file.Stat() 18 if err != nil { 19 return nil, fmt.Errorf("failed to stat %s: %w", file.Name(), err) 20 } 21 sys, ok := stat.Sys().(*syscall.Stat_t) 22 if !ok { 23 return nil, fmt.Errorf("files of type %T don't support Fstat", file) 24 } 25 return fileInfo{sys}, nil 26 } 27 28 func (u fileInfo) Size() int64 { 29 return u.Stat_t.Size 30 } 31 32 func (u fileInfo) SetOwnerAndGroup(name string) error { 33 return os.Chown(name, int(u.Uid), int(u.Gid)) 34 } 35 36 func (u fileInfo) HaveSameOwnerAndGroup(other SysInfo) bool { 37 ou := other.(fileInfo) 38 return u.Uid == ou.Uid && u.Gid == ou.Gid 39 } 40 41 func (u fileInfo) String() string { 42 return fmt.Sprintf("CTIME %v, UID %d, GID %d", u.BirthTime(), u.Uid, u.Gid) 43 } 44 45 func (u fileInfo) BirthTime() time.Time { return time.Unix(u.Birthtimespec.Unix()) } 46 func (u fileInfo) ModifyTime() time.Time { return time.Unix(u.Mtimespec.Unix()) } 47 func (u fileInfo) ChangeTime() time.Time { return time.Unix(u.Ctimespec.Unix()) }