add collection, replication, ttl to each file

This commit is contained in:
Chris Lu
2018-06-10 16:57:32 -07:00
parent f1273073fc
commit 98110c1697
8 changed files with 179 additions and 141 deletions

View File

@@ -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 {

View File

@@ -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
}