entry.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package filer2
  2. import (
  3. "os"
  4. "time"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. )
  7. type Attr struct {
  8. Mtime time.Time // time of last modification
  9. Crtime time.Time // time of creation (OS X only)
  10. Mode os.FileMode // file mode
  11. Uid uint32 // owner uid
  12. Gid uint32 // group gid
  13. Mime string // mime type
  14. Replication string // replication
  15. Collection string // collection name
  16. TtlSec int32 // ttl in seconds
  17. UserName string
  18. GroupNames []string
  19. SymlinkTarget string
  20. }
  21. func (attr Attr) IsDirectory() bool {
  22. return attr.Mode&os.ModeDir > 0
  23. }
  24. type Entry struct {
  25. FullPath
  26. Attr
  27. // the following is for files
  28. Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
  29. }
  30. func (entry *Entry) Size() uint64 {
  31. return TotalSize(entry.Chunks)
  32. }
  33. func (entry *Entry) Timestamp() time.Time {
  34. if entry.IsDirectory() {
  35. return entry.Crtime
  36. } else {
  37. return entry.Mtime
  38. }
  39. }
  40. func (entry *Entry) ToProtoEntry() *filer_pb.Entry {
  41. if entry == nil {
  42. return nil
  43. }
  44. return &filer_pb.Entry{
  45. Name: entry.FullPath.Name(),
  46. IsDirectory: entry.IsDirectory(),
  47. Attributes: EntryAttributeToPb(entry),
  48. Chunks: entry.Chunks,
  49. }
  50. }
  51. func (entry *Entry) ToProtoFullEntry() *filer_pb.FullEntry {
  52. if entry == nil {
  53. return nil
  54. }
  55. dir, _ := entry.FullPath.DirAndName()
  56. return &filer_pb.FullEntry{
  57. Dir: dir,
  58. Entry: entry.ToProtoEntry(),
  59. }
  60. }