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.

83 lines
1.8 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 filer2
  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. }
  23. func (attr Attr) IsDirectory() bool {
  24. return attr.Mode&os.ModeDir > 0
  25. }
  26. type Entry struct {
  27. util.FullPath
  28. Attr
  29. Extended map[string][]byte
  30. // the following is for files
  31. Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
  32. }
  33. func (entry *Entry) Size() uint64 {
  34. return TotalSize(entry.Chunks)
  35. }
  36. func (entry *Entry) Timestamp() time.Time {
  37. if entry.IsDirectory() {
  38. return entry.Crtime
  39. } else {
  40. return entry.Mtime
  41. }
  42. }
  43. func (entry *Entry) ToProtoEntry() *filer_pb.Entry {
  44. if entry == nil {
  45. return nil
  46. }
  47. return &filer_pb.Entry{
  48. Name: entry.FullPath.Name(),
  49. IsDirectory: entry.IsDirectory(),
  50. Attributes: EntryAttributeToPb(entry),
  51. Chunks: entry.Chunks,
  52. Extended: entry.Extended,
  53. }
  54. }
  55. func (entry *Entry) ToProtoFullEntry() *filer_pb.FullEntry {
  56. if entry == nil {
  57. return nil
  58. }
  59. dir, _ := entry.FullPath.DirAndName()
  60. return &filer_pb.FullEntry{
  61. Dir: dir,
  62. Entry: entry.ToProtoEntry(),
  63. }
  64. }
  65. func FromPbEntry(dir string, entry *filer_pb.Entry) *Entry {
  66. return &Entry{
  67. FullPath: util.NewFullPath(dir, entry.Name),
  68. Attr: PbToEntryAttribute(entry.Attributes),
  69. Chunks: entry.Chunks,
  70. }
  71. }