mount: fix problems found in issue 1182

fix https://github.com/chrislusf/seaweedfs/issues/1182

always use the non-duplicated fs.Node
Forget() the fs.Node
Rename will also use the right fs.Node
Avoid using the same file handle for the same file
This commit is contained in:
Chris Lu
2020-01-20 20:21:01 -08:00
parent 630f72f8c5
commit a990ef2106
5 changed files with 117 additions and 44 deletions

View File

@@ -15,10 +15,7 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
newDir := newDirectory.(*Dir)
glog.V(4).Infof("dir Rename %s/%s => %s/%s", dir.Path, req.OldName, newDir.Path, req.NewName)
dir.wfs.cacheDelete(filer2.NewFullPath(newDir.Path, req.NewName))
dir.wfs.cacheDelete(filer2.NewFullPath(dir.Path, req.OldName))
return dir.wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
err := dir.wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.AtomicRenameEntryRequest{
OldDirectory: dir.Path,
@@ -36,4 +33,27 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
return nil
})
if err == nil {
oldPath := filer2.NewFullPath(dir.Path, req.OldName)
dir.wfs.cacheDelete(filer2.NewFullPath(newDir.Path, req.NewName))
dir.wfs.cacheDelete(oldPath)
oldFileNode := dir.wfs.getNode(oldPath, func() fs.Node {
return nil
})
newDirNode := dir.wfs.getNode(filer2.FullPath(dir.Path), func() fs.Node {
return nil
})
if oldFileNode != nil {
oldFile := oldFileNode.(*File)
oldFile.Name = req.NewName
if newDirNode != nil {
oldFile.dir = newDirNode.(*Dir)
}
}
dir.wfs.forgetNode(oldPath)
}
return err
}