Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix nested rename #6

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions zboxcore/sdk/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func ValidateRemoteFileName(remotePath string) error {

type subDirRequest struct {
opType string
subOpType string
remotefilepath string
destPath string
allocationObj *Allocation
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions zboxcore/sdk/moveworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 16 additions & 3 deletions zboxcore/sdk/renameworker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading