aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/file.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-05-14 02:02:17 -0700
committerChris Lu <chris.lu@gmail.com>2018-05-14 02:02:17 -0700
commit58954bf46f5098c1181920bd04ac9e45f6b97913 (patch)
tree383aa901b80d84992df019dbb6a5c0e7ceaa6b9e /weed/filesys/file.go
parent67401f190851f645e54687c502f9af6ad0e6651d (diff)
downloadseaweedfs-58954bf46f5098c1181920bd04ac9e45f6b97913.tar.xz
seaweedfs-58954bf46f5098c1181920bd04ac9e45f6b97913.zip
pass file attributes from filer to mount
Diffstat (limited to 'weed/filesys/file.go')
-rw-r--r--weed/filesys/file.go48
1 files changed, 35 insertions, 13 deletions
diff --git a/weed/filesys/file.go b/weed/filesys/file.go
index e4c79c055..b4a447fa6 100644
--- a/weed/filesys/file.go
+++ b/weed/filesys/file.go
@@ -9,6 +9,9 @@ import (
"bazil.org/fuse/fs"
"github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
+ "path/filepath"
+ "os"
+ "time"
)
var _ = fs.Node(&File{})
@@ -22,29 +25,48 @@ var _ = fs.HandleWriter(&File{})
type File struct {
FileId filer.FileId
Name string
+ dir *Dir
wfs *WFS
}
func (file *File) Attr(context context.Context, attr *fuse.Attr) error {
- attr.Mode = 0444
- return file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
+ fullPath := filepath.Join(file.dir.Path, file.Name)
+ item := file.wfs.listDirectoryEntriesCache.Get(fullPath)
+ var attributes *filer_pb.FuseAttributes
+ if item != nil {
+ attributes = item.Value().(*filer_pb.FuseAttributes)
+ glog.V(1).Infof("read cached file %v attributes", file.Name)
+ } else {
+ err := file.wfs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error {
+
+ request := &filer_pb.GetFileAttributesRequest{
+ Name: file.Name,
+ ParentDir: file.dir.Path,
+ }
+
+ glog.V(1).Infof("read file size: %v", request)
+ resp, err := client.GetFileAttributes(context, request)
+ if err != nil {
+ return err
+ }
+
+ attributes = resp.Attributes
+
+ return nil
+ })
- request := &filer_pb.GetFileAttributesRequest{
- Name: file.Name,
- ParentDir: "", //TODO add parent folder
- FileId: string(file.FileId),
- }
-
- glog.V(1).Infof("read file size: %v", request)
- resp, err := client.GetFileAttributes(context, request)
if err != nil {
return err
}
+ }
- attr.Size = resp.Attributes.FileSize
+ attr.Mode = os.FileMode(attributes.FileMode)
+ attr.Size = attributes.FileSize
+ attr.Mtime = time.Unix(attributes.Mtime, 0)
+ attr.Gid = attributes.Gid
+ attr.Uid = attributes.Uid
+ return nil
- return nil
- })
}
func (file *File) ReadAll(ctx context.Context) (content []byte, err error) {