aboutsummaryrefslogtreecommitdiff
path: root/weed/filer2
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer2')
-rw-r--r--weed/filer2/entry.go15
-rw-r--r--weed/filer2/entry_codec.go50
2 files changed, 44 insertions, 21 deletions
diff --git a/weed/filer2/entry.go b/weed/filer2/entry.go
index a2f8b91ef..82bc00b27 100644
--- a/weed/filer2/entry.go
+++ b/weed/filer2/entry.go
@@ -8,12 +8,15 @@ import (
)
type Attr struct {
- Mtime time.Time // time of last modification
- Crtime time.Time // time of creation (OS X only)
- Mode os.FileMode // file mode
- Uid uint32 // owner uid
- Gid uint32 // group gid
- Mime string
+ Mtime time.Time // time of last modification
+ Crtime time.Time // time of creation (OS X only)
+ Mode os.FileMode // file mode
+ Uid uint32 // owner uid
+ Gid uint32 // group gid
+ Mime string // mime type
+ Replication string // replication
+ Collection string // collection name
+ TtlSec int32 // ttl in seconds
}
func (attr Attr) IsDirectory() bool {
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
+}