diff options
Diffstat (limited to 'weed/filer2/entry_codec.go')
| -rw-r--r-- | weed/filer2/entry_codec.go | 50 |
1 files changed, 35 insertions, 15 deletions
diff --git a/weed/filer2/entry_codec.go b/weed/filer2/entry_codec.go index 7585203e9..671568b75 100644 --- a/weed/filer2/entry_codec.go +++ b/weed/filer2/entry_codec.go @@ -11,15 +11,8 @@ import ( func (entry *Entry) EncodeAttributesAndChunks() ([]byte, error) { 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, - Mime: entry.Mime, - }, - Chunks: entry.Chunks, + Attributes: EntryAttributeToPb(entry), + Chunks: entry.Chunks, } return proto.Marshal(message) } @@ -32,14 +25,41 @@ func (entry *Entry) DecodeAttributesAndChunks(blob []byte) error { 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 - entry.Attr.Mime = message.Attributes.Mime + entry.Attr = PbToEntryAttribute(message.Attributes) entry.Chunks = message.Chunks return nil } + +func EntryAttributeToPb(entry *Entry) *filer_pb.FuseAttributes { + + return &filer_pb.FuseAttributes{ + Crtime: entry.Attr.Crtime.Unix(), + Mtime: entry.Attr.Mtime.Unix(), + FileMode: uint32(entry.Attr.Mode), + Uid: entry.Uid, + Gid: entry.Gid, + Mime: entry.Mime, + Collection: entry.Attr.Collection, + Replication: entry.Attr.Replication, + TtlSec: entry.Attr.TtlSec, + } +} + +func PbToEntryAttribute(attr *filer_pb.FuseAttributes) Attr { + + t := Attr{} + + t.Crtime = time.Unix(attr.Crtime, 0) + t.Mtime = time.Unix(attr.Mtime, 0) + t.Mode = os.FileMode(attr.FileMode) + t.Uid = attr.Uid + t.Gid = attr.Gid + t.Mime = attr.Mime + t.Collection = attr.Collection + t.Replication = attr.Replication + t.TtlSec = attr.TtlSec + + return t +} |
