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.

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