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.

43 lines
1.0 KiB

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