2018-05-26 06:27:06 +00:00
|
|
|
package filer2
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Attr struct {
|
2018-12-26 06:45:44 +00:00
|
|
|
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
|
|
|
|
UserName string
|
|
|
|
GroupNames []string
|
|
|
|
SymlinkTarget string
|
2018-05-26 06:27:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-27 18:52:26 +00:00
|
|
|
func (attr Attr) IsDirectory() bool {
|
2018-05-26 06:27:06 +00:00
|
|
|
return attr.Mode&os.ModeDir > 0
|
|
|
|
}
|
|
|
|
|
|
|
|
type Entry struct {
|
|
|
|
FullPath
|
|
|
|
|
|
|
|
Attr
|
2019-12-18 05:10:26 +00:00
|
|
|
Extended map[string][]byte
|
2018-05-26 06:27:06 +00:00
|
|
|
|
|
|
|
// the following is for files
|
|
|
|
Chunks []*filer_pb.FileChunk `json:"chunks,omitempty"`
|
|
|
|
}
|
|
|
|
|
2018-05-26 10:49:46 +00:00
|
|
|
func (entry *Entry) Size() uint64 {
|
2018-05-26 06:27:06 +00:00
|
|
|
return TotalSize(entry.Chunks)
|
|
|
|
}
|
|
|
|
|
2018-05-26 10:49:46 +00:00
|
|
|
func (entry *Entry) Timestamp() time.Time {
|
2018-05-26 06:27:06 +00:00
|
|
|
if entry.IsDirectory() {
|
|
|
|
return entry.Crtime
|
|
|
|
} else {
|
|
|
|
return entry.Mtime
|
|
|
|
}
|
|
|
|
}
|
2018-11-03 19:43:45 +00:00
|
|
|
|
|
|
|
func (entry *Entry) ToProtoEntry() *filer_pb.Entry {
|
|
|
|
if entry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &filer_pb.Entry{
|
2019-04-16 07:44:31 +00:00
|
|
|
Name: entry.FullPath.Name(),
|
2018-11-03 19:43:45 +00:00
|
|
|
IsDirectory: entry.IsDirectory(),
|
|
|
|
Attributes: EntryAttributeToPb(entry),
|
|
|
|
Chunks: entry.Chunks,
|
2019-12-18 05:10:26 +00:00
|
|
|
Extended: entry.Extended,
|
2018-11-03 19:43:45 +00:00
|
|
|
}
|
|
|
|
}
|
2019-04-16 07:44:31 +00:00
|
|
|
|
|
|
|
func (entry *Entry) ToProtoFullEntry() *filer_pb.FullEntry {
|
|
|
|
if entry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
dir, _ := entry.FullPath.DirAndName()
|
|
|
|
return &filer_pb.FullEntry{
|
|
|
|
Dir: dir,
|
|
|
|
Entry: entry.ToProtoEntry(),
|
|
|
|
}
|
|
|
|
}
|