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.

73 lines
1.5 KiB

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