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.

45 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/filer2"
  6. "github.com/chrislusf/seaweedfs/weed/glog"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  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. glog.V(4).Infof("dir Rename %s/%s => %s/%s", dir.Path, req.OldName, newDir.Path, req.NewName)
  14. err := dir.wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
  15. request := &filer_pb.AtomicRenameEntryRequest{
  16. OldDirectory: dir.Path,
  17. OldName: req.OldName,
  18. NewDirectory: newDir.Path,
  19. NewName: req.NewName,
  20. }
  21. _, err := client.AtomicRenameEntry(ctx, request)
  22. if err != nil {
  23. return fmt.Errorf("renaming %s/%s => %s/%s: %v", dir.Path, req.OldName, newDir.Path, req.NewName, err)
  24. }
  25. return nil
  26. })
  27. if err == nil {
  28. oldpath := string(filer2.NewFullPath(dir.Path, req.OldName))
  29. newpath := string(filer2.NewFullPath(newDir.Path, req.NewName))
  30. dir.wfs.listDirectoryEntriesCache.Delete(oldpath)
  31. dir.wfs.listDirectoryEntriesCache.Delete(newpath)
  32. }
  33. return err
  34. }