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.

65 lines
1.4 KiB

7 years ago
7 years ago
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. "fmt"
  6. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  7. "github.com/gogo/protobuf/proto"
  8. )
  9. func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) {
  10. message := &filer_pb.Entry{
  11. Attributes: EntryAttributeToPb(entry),
  12. Chunks: entry.Chunks,
  13. }
  14. return proto.Marshal(message)
  15. }
  16. func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error {
  17. message := &filer_pb.Entry{}
  18. if err := proto.UnmarshalMerge(blob, message); err != nil {
  19. return fmt.Errorf("decoding value blob for %s: %v", entry.FullPath, err)
  20. }
  21. entry.Attr = PbToEntryAttribute(message.Attributes)
  22. entry.Chunks = message.Chunks
  23. return nil
  24. }
  25. func EntryAttributeToPb(entry *Entry) *filer_pb.FuseAttributes {
  26. return &filer_pb.FuseAttributes{
  27. Crtime: entry.Attr.Crtime.Unix(),
  28. Mtime: entry.Attr.Mtime.Unix(),
  29. FileMode: uint32(entry.Attr.Mode),
  30. Uid: entry.Uid,
  31. Gid: entry.Gid,
  32. Mime: entry.Mime,
  33. Collection: entry.Attr.Collection,
  34. Replication: entry.Attr.Replication,
  35. TtlSec: entry.Attr.TtlSec,
  36. }
  37. }
  38. func PbToEntryAttribute(attr *filer_pb.FuseAttributes) Attr {
  39. t := Attr{}
  40. t.Crtime = time.Unix(attr.Crtime, 0)
  41. t.Mtime = time.Unix(attr.Mtime, 0)
  42. t.Mode = os.FileMode(attr.FileMode)
  43. t.Uid = attr.Uid
  44. t.Gid = attr.Gid
  45. t.Mime = attr.Mime
  46. t.Collection = attr.Collection
  47. t.Replication = attr.Replication
  48. t.TtlSec = attr.TtlSec
  49. return t
  50. }