stat_unix.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // +build !windows
  2. package system
  3. import "syscall"
  4. // StatT type contains status of a file. It contains metadata
  5. // like permission, owner, group, size, etc about a file.
  6. type StatT struct {
  7. mode uint32
  8. uid uint32
  9. gid uint32
  10. rdev uint64
  11. size int64
  12. mtim syscall.Timespec
  13. }
  14. // Mode returns file's permission mode.
  15. func (s StatT) Mode() uint32 {
  16. return s.mode
  17. }
  18. // UID returns file's user id of owner.
  19. func (s StatT) UID() uint32 {
  20. return s.uid
  21. }
  22. // GID returns file's group id of owner.
  23. func (s StatT) GID() uint32 {
  24. return s.gid
  25. }
  26. // Rdev returns file's device ID (if it's special file).
  27. func (s StatT) Rdev() uint64 {
  28. return s.rdev
  29. }
  30. // Size returns file's size.
  31. func (s StatT) Size() int64 {
  32. return s.size
  33. }
  34. // Mtim returns file's last modification time.
  35. func (s StatT) Mtim() syscall.Timespec {
  36. return s.mtim
  37. }
  38. // Stat takes a path to a file and returns
  39. // a system.StatT type pertaining to that file.
  40. //
  41. // Throws an error if the file does not exist
  42. func Stat(path string) (*StatT, error) {
  43. s := &syscall.Stat_t{}
  44. if err := syscall.Stat(path, s); err != nil {
  45. return nil, err
  46. }
  47. return fromStatT(s)
  48. }