diff --git a/zboxcore/sdk/common.go b/zboxcore/sdk/common.go index 90de2635e..3d69f7cee 100644 --- a/zboxcore/sdk/common.go +++ b/zboxcore/sdk/common.go @@ -126,6 +126,7 @@ func ValidateRemoteFileName(remotePath string) error { type subDirRequest struct { opType string + subOpType string remotefilepath string destPath string allocationObj *Allocation @@ -157,8 +158,13 @@ func (req *subDirRequest) processSubDirectories() error { if ref.PathLevel > pathLevel { pathLevel = ref.PathLevel } - basePath := strings.TrimPrefix(path.Dir(ref.Path), path.Dir(req.remotefilepath)) - destPath := path.Join(req.destPath, basePath) + var destPath string + if req.subOpType == constants.FileOperationRename { + destPath = path.Dir(strings.Replace(ref.Path, req.remotefilepath, req.destPath, 1)) + } else { + basePath := strings.TrimPrefix(path.Dir(ref.Path), path.Dir(req.remotefilepath)) + destPath = path.Join(req.destPath, basePath) + } op := OperationRequest{ OperationType: req.opType, RemotePath: ref.Path, @@ -197,8 +203,13 @@ func (req *subDirRequest) processSubDirectories() error { if ref.Type == fileref.FILE { continue } - basePath := strings.TrimPrefix(path.Dir(ref.Path), path.Dir(req.remotefilepath)) - destPath := path.Join(req.destPath, basePath) + var destPath string + if req.subOpType == constants.FileOperationRename { + destPath = path.Dir(strings.Replace(ref.Path, req.remotefilepath, req.destPath, 1)) + } else { + basePath := strings.TrimPrefix(path.Dir(ref.Path), path.Dir(req.remotefilepath)) + destPath = path.Join(req.destPath, basePath) + } op := OperationRequest{ OperationType: req.opType, RemotePath: ref.Path, diff --git a/zboxcore/sdk/moveworker.go b/zboxcore/sdk/moveworker.go index 19d3837ae..b5e7bc17e 100644 --- a/zboxcore/sdk/moveworker.go +++ b/zboxcore/sdk/moveworker.go @@ -226,6 +226,7 @@ func (req *MoveRequest) ProcessWithBlobbers() ([]fileref.RefEntity, error) { ctx: req.ctx, consensusThresh: req.consensusThresh, opType: constants.FileOperationMove, + subOpType: constants.FileOperationMove, mask: req.moveMask, } err := subRequest.processSubDirectories() diff --git a/zboxcore/sdk/renameworker.go b/zboxcore/sdk/renameworker.go index d0a317725..d9f2cdd84 100644 --- a/zboxcore/sdk/renameworker.go +++ b/zboxcore/sdk/renameworker.go @@ -220,13 +220,26 @@ func (req *RenameRequest) ProcessWithBlobbers() ([]fileref.RefEntity, error) { req.renameMask = req.renameMask.And(zboxutil.NewUint128(1).Lsh(uint64(ind)).Not()) } } + subRequest := &subDirRequest{ + allocationObj: req.allocationObj, + remotefilepath: req.remotefilepath, + destPath: path.Join(path.Dir(req.remotefilepath), req.newName), + ctx: req.ctx, + consensusThresh: req.consensus.consensusThresh, + opType: constants.FileOperationMove, + subOpType: constants.FileOperationRename, + mask: req.renameMask, + } + err := subRequest.processSubDirectories() + if err != nil { + return nil, err + } op := OperationRequest{ - OperationType: constants.FileOperationMove, + OperationType: constants.FileOperationDelete, RemotePath: req.remotefilepath, - DestPath: path.Join(path.Dir(req.remotefilepath), req.newName), Mask: &req.renameMask, } - err := req.allocationObj.DoMultiOperation([]OperationRequest{op}) + err = req.allocationObj.DoMultiOperation([]OperationRequest{op}) if err != nil { return nil, err }