diff options
| author | Chris Lu <chris.lu@gmail.com> | 2021-03-12 00:36:29 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2021-03-12 00:36:38 -0800 |
| commit | 7d57664c2d80f2b7d3eb4cecc57a3275bafee44d (patch) | |
| tree | 86d2a46c937bc75faafca7bae9709fd5a4b9059e /weed/filesys/dir.go | |
| parent | d41202f1b3b6e8a463eec854b721a57dffc7cf66 (diff) | |
| download | seaweedfs-7d57664c2d80f2b7d3eb4cecc57a3275bafee44d.tar.xz seaweedfs-7d57664c2d80f2b7d3eb4cecc57a3275bafee44d.zip | |
mount: internals switch to filer.Entry instead of protobuf
Diffstat (limited to 'weed/filesys/dir.go')
| -rw-r--r-- | weed/filesys/dir.go | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/weed/filesys/dir.go b/weed/filesys/dir.go index 33e1a0a3a..6168425af 100644 --- a/weed/filesys/dir.go +++ b/weed/filesys/dir.go @@ -1,7 +1,6 @@ package filesys import ( - "bytes" "context" "math" "os" @@ -22,7 +21,7 @@ import ( type Dir struct { name string wfs *WFS - entry *filer_pb.Entry + entry *filer.Entry parent *Dir } @@ -59,11 +58,11 @@ func (dir *Dir) Attr(ctx context.Context, attr *fuse.Attr) error { } // attr.Inode = util.FullPath(dir.FullPath()).AsInode() - attr.Mode = os.FileMode(dir.entry.Attributes.FileMode) | os.ModeDir - attr.Mtime = time.Unix(dir.entry.Attributes.Mtime, 0) - attr.Crtime = time.Unix(dir.entry.Attributes.Crtime, 0) - attr.Gid = dir.entry.Attributes.Gid - attr.Uid = dir.entry.Attributes.Uid + attr.Mode = dir.entry.Attr.Mode | os.ModeDir + attr.Mtime = dir.entry.Attr.Mtime + attr.Crtime = dir.entry.Attr.Crtime + attr.Gid = dir.entry.Attr.Gid + attr.Uid = dir.entry.Attr.Uid glog.V(4).Infof("dir Attr %s, attr: %+v", dir.FullPath(), attr) @@ -103,12 +102,13 @@ func (dir *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error { } func (dir *Dir) newFile(name string, entry *filer_pb.Entry) fs.Node { - f := dir.wfs.fsNodeCache.EnsureFsNode(util.NewFullPath(dir.FullPath(), name), func() fs.Node { + dirPath := dir.FullPath() + f := dir.wfs.fsNodeCache.EnsureFsNode(util.NewFullPath(dirPath, name), func() fs.Node { return &File{ Name: name, dir: dir, wfs: dir.wfs, - entry: entry, + entry: filer.FromPbEntry(dirPath, entry), entryViewCache: nil, } }) @@ -119,7 +119,7 @@ func (dir *Dir) newFile(name string, entry *filer_pb.Entry) fs.Node { func (dir *Dir) newDirectory(fullpath util.FullPath, entry *filer_pb.Entry) fs.Node { d := dir.wfs.fsNodeCache.EnsureFsNode(fullpath, func() fs.Node { - return &Dir{name: entry.Name, wfs: dir.wfs, entry: entry, parent: dir} + return &Dir{name: entry.Name, wfs: dir.wfs, entry: filer.FromPbEntry(dir.FullPath(), entry), parent: dir} }) d.(*Dir).parent = dir // in case dir node was created later return d @@ -436,19 +436,19 @@ func (dir *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fus } if req.Valid.Mode() { - dir.entry.Attributes.FileMode = uint32(req.Mode) + dir.entry.Attr.Mode = req.Mode } if req.Valid.Uid() { - dir.entry.Attributes.Uid = req.Uid + dir.entry.Attr.Uid = req.Uid } if req.Valid.Gid() { - dir.entry.Attributes.Gid = req.Gid + dir.entry.Attr.Gid = req.Gid } if req.Valid.Mtime() { - dir.entry.Attributes.Mtime = req.Mtime.Unix() + dir.entry.Attr.Mtime = req.Mtime } return dir.saveEntry() @@ -527,12 +527,14 @@ func (dir *Dir) saveEntry() error { return dir.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error { - dir.wfs.mapPbIdFromLocalToFiler(dir.entry) - defer dir.wfs.mapPbIdFromFilerToLocal(dir.entry) + pbEntry := dir.entry.ToProtoEntry() + + dir.wfs.mapPbIdFromLocalToFiler(pbEntry) + defer dir.wfs.mapPbIdFromFilerToLocal(pbEntry) request := &filer_pb.UpdateEntryRequest{ Directory: parentDir, - Entry: dir.entry, + Entry: pbEntry, Signatures: []int32{dir.wfs.signature}, } @@ -550,25 +552,5 @@ func (dir *Dir) saveEntry() error { } func (dir *Dir) FullPath() string { - var parts []string - for p := dir; p != nil; p = p.parent { - if strings.HasPrefix(p.name, "/") { - if len(p.name) > 1 { - parts = append(parts, p.name[1:]) - } - } else { - parts = append(parts, p.name) - } - } - - if len(parts) == 0 { - return "/" - } - - var buf bytes.Buffer - for i := len(parts) - 1; i >= 0; i-- { - buf.WriteString("/") - buf.WriteString(parts[i]) - } - return buf.String() + return string(dir.entry.FullPath) } |
