stat_windows.go 1015 B

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