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.

45 lines
1.1 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: &filer_pb.FuseAttributes{
  12. Crtime: entry.Attr.Crtime.Unix(),
  13. Mtime: entry.Attr.Mtime.Unix(),
  14. FileMode: uint32(entry.Attr.Mode),
  15. Uid: entry.Uid,
  16. Gid: entry.Gid,
  17. Mime: entry.Mime,
  18. },
  19. Chunks: entry.Chunks,
  20. }
  21. return proto.Marshal(message)
  22. }
  23. func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error {
  24. message := &filer_pb.Entry{}
  25. if err := proto.UnmarshalMerge(blob, message); err != nil {
  26. return fmt.Errorf("decoding value blob for %s: %v", entry.FullPath, err)
  27. }
  28. entry.Attr.Crtime = time.Unix(message.Attributes.Crtime, 0)
  29. entry.Attr.Mtime = time.Unix(message.Attributes.Mtime, 0)
  30. entry.Attr.Mode = os.FileMode(message.Attributes.FileMode)
  31. entry.Attr.Uid = message.Attributes.Uid
  32. entry.Attr.Gid = message.Attributes.Gid
  33. entry.Attr.Mime = message.Attributes.Mime
  34. entry.Chunks = message.Chunks
  35. return nil
  36. }