You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.2 KiB

5 years ago
5 years ago
5 years ago
5 years ago
  1. package filesys
  2. import (
  3. "context"
  4. "github.com/chrislusf/seaweedfs/weed/glog"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/chrislusf/seaweedfs/weed/util"
  7. "github.com/seaweedfs/fuse"
  8. "github.com/seaweedfs/fuse/fs"
  9. )
  10. func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
  11. newDir := newDirectory.(*Dir)
  12. newPath := util.NewFullPath(newDir.FullPath(), req.NewName)
  13. oldPath := util.NewFullPath(dir.FullPath(), req.OldName)
  14. glog.V(4).Infof("dir Rename %s => %s", oldPath, newPath)
  15. err := dir.wfs.WithFilerClient(func(client filer_pb.SeaweedFilerClient) error {
  16. request := &filer_pb.AtomicRenameEntryRequest{
  17. OldDirectory: dir.FullPath(),
  18. OldName: req.OldName,
  19. NewDirectory: newDir.FullPath(),
  20. NewName: req.NewName,
  21. }
  22. _, err := client.AtomicRenameEntry(context.Background(), request)
  23. if err != nil {
  24. glog.V(0).Infof("dir Rename %s => %s : %v", oldPath, newPath, err)
  25. return fuse.EIO
  26. }
  27. return nil
  28. })
  29. if err == nil {
  30. dir.wfs.cacheDelete(newPath)
  31. dir.wfs.cacheDelete(oldPath)
  32. // fmt.Printf("rename path: %v => %v\n", oldPath, newPath)
  33. dir.wfs.fsNodeCache.Move(oldPath, newPath)
  34. }
  35. return err
  36. }