2018-05-26 14:27:06 +08:00
|
|
|
package filer2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2018-05-28 02:52:26 +08:00
|
|
|
"fmt"
|
2018-05-26 14:27:06 +08:00
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/gogo/protobuf/proto"
|
|
|
|
)
|
|
|
|
|
2018-05-26 18:49:46 +08:00
|
|
|
func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) {
|
2018-05-26 14:27:06 +08:00
|
|
|
message := &filer_pb.Entry{
|
|
|
|
Attributes: &filer_pb.FuseAttributes{
|
|
|
|
Crtime: entry.Attr.Crtime.Unix(),
|
|
|
|
Mtime: entry.Attr.Mtime.Unix(),
|
|
|
|
FileMode: uint32(entry.Attr.Mode),
|
|
|
|
Uid: entry.Uid,
|
|
|
|
Gid: entry.Gid,
|
2018-05-31 11:24:57 +08:00
|
|
|
Mime: entry.Mime,
|
2018-05-26 14:27:06 +08:00
|
|
|
},
|
|
|
|
Chunks: entry.Chunks,
|
|
|
|
}
|
|
|
|
return proto.Marshal(message)
|
|
|
|
}
|
|
|
|
|
2018-05-28 02:52:26 +08:00
|
|
|
func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error {
|
2018-05-26 14:27:06 +08:00
|
|
|
|
|
|
|
message := &filer_pb.Entry{}
|
|
|
|
|
|
|
|
if err := proto.UnmarshalMerge(blob, message); err != nil {
|
|
|
|
return fmt.Errorf("decoding value blob for %s: %v", entry.FullPath, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
entry.Attr.Crtime = time.Unix(message.Attributes.Crtime, 0)
|
|
|
|
entry.Attr.Mtime = time.Unix(message.Attributes.Mtime, 0)
|
|
|
|
entry.Attr.Mode = os.FileMode(message.Attributes.FileMode)
|
|
|
|
entry.Attr.Uid = message.Attributes.Uid
|
|
|
|
entry.Attr.Gid = message.Attributes.Gid
|
2018-05-31 11:24:57 +08:00
|
|
|
entry.Attr.Mime = message.Attributes.Mime
|
2018-05-26 14:27:06 +08:00
|
|
|
|
|
|
|
entry.Chunks = message.Chunks
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|