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.

59 lines
1.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 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. }
  20. func (attr Attr) IsDirectory() bool {
  21. return attr.Mode&os.ModeDir > 0
  22. }
  23. type Entry struct {
  24. FullPath
  25. Attr
  26. // the following is for files
  27. Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
  28. }
  29. func (entry *Entry) Size() uint64 {
  30. return TotalSize(entry.Chunks)
  31. }
  32. func (entry *Entry) Timestamp() time.Time {
  33. if entry.IsDirectory() {
  34. return entry.Crtime
  35. } else {
  36. return entry.Mtime
  37. }
  38. }
  39. func (entry *Entry) ToProtoEntry() *filer_pb.Entry {
  40. if entry == nil {
  41. return nil
  42. }
  43. return &filer_pb.Entry{
  44. Name: string(entry.FullPath),
  45. IsDirectory: entry.IsDirectory(),
  46. Attributes: EntryAttributeToPb(entry),
  47. Chunks: entry.Chunks,
  48. }
  49. }