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

[Move Object] Bucket handle integration #2840

Merged
merged 14 commits into from
Dec 27, 2024
44 changes: 42 additions & 2 deletions internal/storage/bucket_handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,48 @@ func (bh *bucketHandle) DeleteFolder(ctx context.Context, folderName string) (er
}

func (bh *bucketHandle) MoveObject(ctx context.Context, req *gcs.MoveObjectRequest) (*gcs.Object, error) {
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
// TODO: Implement it.
return nil, nil
var o *gcs.Object
var err error

obj := bh.bucket.Object(req.SrcName)

// Switching to the requested generation of source object.
if req.SrcGeneration != 0 {
obj = obj.Generation(req.SrcGeneration)
}

// Putting a condition that the metaGeneration of source should match *req.SrcMetaGenerationPrecondition for move operation to occur.
if req.SrcMetaGenerationPrecondition != nil {
obj = obj.If(storage.Conditions{MetagenerationMatch: *req.SrcMetaGenerationPrecondition})
}

dstMoveObject := storage.MoveObjectDestination{
Object: req.DstName,
Conditions: nil,
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}

attrs, err := obj.Move(ctx, dstMoveObject)
if err == nil {
// Converting objAttrs to type *Object
o = storageutil.ObjectAttrsToBucketObject(attrs)
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}

// If storage object does not exist, httpclient is returning ErrObjectNotExist error instead of googleapi error
// https://github.com/GoogleCloudPlatform/gcsfuse/blob/master/vendor/cloud.google.com/go/storage/http_client.go#L516
switch ee := err.(type) {
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
case *googleapi.Error:
if ee.Code == http.StatusPreconditionFailed {
err = &gcs.PreconditionError{Err: ee}
}
default:
if err == storage.ErrObjectNotExist {
err = &gcs.NotFoundError{Err: storage.ErrObjectNotExist}
} else {
err = fmt.Errorf("error in updating object: %w", err)
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}
}

return o, nil
Tulsishah marked this conversation as resolved.
Show resolved Hide resolved
}

func (bh *bucketHandle) RenameFolder(ctx context.Context, folderName string, destinationFolderId string) (folder *gcs.Folder, err error) {
Expand Down
Loading