You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.9 KiB

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