From fa0dab60299e73acfb8bca72b50184722db8e3ab Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Sat, 3 Jul 2021 02:59:35 -0700 Subject: [PATCH] mount: rename also recursively move file handles related to https://github.com/chrislusf/seaweedfs/issues/2169 --- weed/filesys/dir_rename.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go index 27a14d5c6..f69339a14 100644 --- a/weed/filesys/dir_rename.go +++ b/weed/filesys/dir_rename.go @@ -63,18 +63,6 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector return fuse.EIO } - // change file handle - dir.wfs.handlesLock.Lock() - defer dir.wfs.handlesLock.Unlock() - inodeId := oldPath.AsInode() - existingHandle, found := dir.wfs.handles[inodeId] - glog.V(4).Infof("has open filehandle %s: %v", oldPath, found) - if !found || existingHandle == nil { - return nil - } - glog.V(4).Infof("opened filehandle %s => %s", oldPath, newPath) - delete(dir.wfs.handles, inodeId) - dir.wfs.handles[newPath.AsInode()] = existingHandle return nil } @@ -83,10 +71,12 @@ func (dir *Dir) moveEntry(ctx context.Context, oldParent util.FullPath, entry *f oldName := entry.Name() + oldPath := oldParent.Child(oldName) + newPath := newParent.Child(newName) if err := dir.moveSelfEntry(ctx, oldParent, entry, newParent, newName, func() error { - oldFsNode := NodeWithId(oldParent.Child(oldName).AsInode()) - newFsNode := NodeWithId(newParent.Child(newName).AsInode()) + oldFsNode := NodeWithId(oldPath.AsInode()) + newFsNode := NodeWithId(newPath.AsInode()) newDirNode, found := dir.wfs.Server.FindInternalNode(NodeWithId(newParent.AsInode())) var newDir *Dir if found { @@ -111,6 +101,16 @@ func (dir *Dir) moveEntry(ctx context.Context, oldParent util.FullPath, entry *f } }) + // change file handle + inodeId := oldPath.AsInode() + dir.wfs.handlesLock.Lock() + if existingHandle, found := dir.wfs.handles[inodeId]; found && existingHandle == nil { + glog.V(4).Infof("opened file handle %s => %s", oldPath, newPath) + delete(dir.wfs.handles, inodeId) + dir.wfs.handles[newPath.AsInode()] = existingHandle + } + dir.wfs.handlesLock.Unlock() + if entry.IsDirectory() { if err := dir.moveFolderSubEntries(ctx, oldParent, oldName, newParent, newName); err != nil { return err @@ -118,7 +118,7 @@ func (dir *Dir) moveEntry(ctx context.Context, oldParent util.FullPath, entry *f } return nil }); err != nil { - return fmt.Errorf("fail to move %s => %s: %v", oldParent.Child(oldName), newParent.Child(newName), err) + return fmt.Errorf("fail to move %s => %s: %v", oldPath, newPath, err) } return nil