diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-01-20 20:21:01 -0800 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-01-20 20:21:01 -0800 |
| commit | a990ef2106a2571d0e2578eecdd856ee74986944 (patch) | |
| tree | 44ac20bd9fc651da33c3171bdac2772522972eaa /weed/filesys/dir_rename.go | |
| parent | 630f72f8c577fba9ca11fee7694e0748af03fadf (diff) | |
| download | seaweedfs-a990ef2106a2571d0e2578eecdd856ee74986944.tar.xz seaweedfs-a990ef2106a2571d0e2578eecdd856ee74986944.zip | |
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
Diffstat (limited to 'weed/filesys/dir_rename.go')
| -rw-r--r-- | weed/filesys/dir_rename.go | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go index 6b68e4ee9..1bd1a6470 100644 --- a/weed/filesys/dir_rename.go +++ b/weed/filesys/dir_rename.go @@ -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 } |
