dir_rename.go 750 B

123456789101112131415161718192021222324252627282930313233
  1. package filesys
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. "github.com/seaweedfs/fuse"
  7. "github.com/seaweedfs/fuse/fs"
  8. )
  9. func (dir *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDirectory fs.Node) error {
  10. newDir := newDirectory.(*Dir)
  11. return dir.wfs.WithFilerClient(ctx, func(client filer_pb.SeaweedFilerClient) error {
  12. request := &filer_pb.AtomicRenameEntryRequest{
  13. OldDirectory: dir.Path,
  14. OldName: req.OldName,
  15. NewDirectory: newDir.Path,
  16. NewName: req.NewName,
  17. }
  18. _, err := client.AtomicRenameEntry(ctx, request)
  19. if err != nil {
  20. return fmt.Errorf("renaming %s/%s => %s/%s: %v", dir.Path, req.OldName, newDir.Path, req.NewName, err)
  21. }
  22. return nil
  23. })
  24. }