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.

52 lines
1.2 KiB

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