aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/dir_rename.go
diff options
context:
space:
mode:
authorHongyanShen <763987993@qq.com>2020-03-11 12:55:24 +0800
committerGitHub <noreply@github.com>2020-03-11 12:55:24 +0800
commit03529fc0c29072f6f26e11ffbd7229cf92dc71ce (patch)
treeed8833386a712c850dcef0815509774681a6ab56 /weed/filesys/dir_rename.go
parent0fca1ae776783b37481549df40f477b7d9248d3c (diff)
parent60f5f05c78a2918d5219c925cea5847759281a2c (diff)
downloadseaweedfs-03529fc0c29072f6f26e11ffbd7229cf92dc71ce.tar.xz
seaweedfs-03529fc0c29072f6f26e11ffbd7229cf92dc71ce.zip
Merge pull request #1 from chrislusf/master
sync
Diffstat (limited to 'weed/filesys/dir_rename.go')
-rw-r--r--weed/filesys/dir_rename.go38
1 files changed, 34 insertions, 4 deletions
diff --git a/weed/filesys/dir_rename.go b/weed/filesys/dir_rename.go
index e72a15758..9b0c0fe6e 100644
--- a/weed/filesys/dir_rename.go
+++ b/weed/filesys/dir_rename.go
@@ -2,7 +2,9 @@ package filesys
import (
"context"
- "fmt"
+
+ "github.com/chrislusf/seaweedfs/weed/filer2"
+ "github.com/chrislusf/seaweedfs/weed/glog"
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
"github.com/seaweedfs/fuse"
"github.com/seaweedfs/fuse/fs"
@@ -11,8 +13,9 @@ import (
func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
newDir := newDirectory.(*Dir)
+ glog.V(4).Infof("dir Rename %s/%s => %s/%s", dir.Path, req.OldName, newDir.Path, req.NewName)
- return dir.wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
+ err := dir.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
request := &filer_pb.AtomicRenameEntryRequest{
OldDirectory: dir.Path,
@@ -21,13 +24,40 @@ func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirector
NewName: req.NewName,
}
- _, err := client.AtomicRenameEntry(ctx, request)
+ _, err := client.AtomicRenameEntry(context.Background(), request)
if err != nil {
- return fmt.Errorf("renaming %s/%s => %s/%s: %v", dir.Path, req.OldName, newDir.Path, req.NewName, err)
+ glog.V(0).Infof("dir Rename %s/%s => %s/%s : %v", dir.Path, req.OldName, newDir.Path, req.NewName, err)
+ return fuse.EIO
}
return nil
})
+ if err == nil {
+ newPath := filer2.NewFullPath(newDir.Path, req.NewName)
+ oldPath := filer2.NewFullPath(dir.Path, req.OldName)
+ dir.wfs.cacheDelete(newPath)
+ 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
+ })
+ dir.wfs.forgetNode(newPath)
+ dir.wfs.forgetNode(oldPath)
+ if oldFileNode != nil && newDirNode != nil {
+ oldFile := oldFileNode.(*File)
+ oldFile.Name = req.NewName
+ oldFile.dir = newDirNode.(*Dir)
+ dir.wfs.getNode(newPath, func() fs.Node {
+ return oldFile
+ })
+
+ }
+ }
+
+ return err
}