Skip to content

Commit

Permalink
fix: dws-1306 cp command fix
Browse files Browse the repository at this point in the history
  • Loading branch information
maratkanov-a committed Sep 19, 2024
1 parent 83b3fef commit 12b67e4
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions miniogw/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,33 +1060,17 @@ func (layer *gatewayLayer) CopyObject(ctx context.Context, srcBucket, srcObject,
return srcInfo, nil
}

object, err := project.CopyObject(ctx, srcBucket, srcObject, destBucket, destObject, nil)
if err != nil {
// TODO how we can improve it, its ugly
if errors.Is(err, uplink.ErrBucketNotFound) {
if strings.Contains(err.Error(), srcBucket) {
return minio.ObjectInfo{}, minio.BucketNotFound{Bucket: srcBucket}
} else if strings.Contains(err.Error(), destBucket) {
return minio.ObjectInfo{}, minio.BucketNotFound{Bucket: destBucket}
}
}
return minio.ObjectInfo{}, ConvertError(err, destBucket, destObject)
}

// TODO most probably we need better condition
if len(srcInfo.UserDefined) > 0 {
// TODO currently we need to set metadata as a separate step because we
// don't have a solution to not override ETag stored in custom metadata
upsertObjectMetadata(srcInfo.UserDefined, object.Custom)

err = project.UpdateObjectMetadata(ctx, destBucket, destObject, srcInfo.UserDefined, nil)
if err != nil {
return minio.ObjectInfo{}, ConvertError(err, destBucket, destObject)
}
object.Custom = uplink.CustomMetadata(srcInfo.UserDefined)
// https://github.com/minio/minio/blob/master/cmd/erasure-server-pool.go#L1348
putOpts := minio.ObjectOptions{
ServerSideEncryption: destOpts.ServerSideEncryption,
UserDefined: srcInfo.UserDefined,
Versioned: destOpts.Versioned,
VersionID: destOpts.VersionID,
MTime: destOpts.MTime,
NoLock: true,
}

return minioObjectInfo(destBucket, "", object), nil
return layer.PutObject(ctx, destBucket, destObject, srcInfo.PutObjReader, putOpts)
}

func (layer *gatewayLayer) DeleteObject(ctx context.Context, bucket, objectPath string, opts minio.ObjectOptions) (objInfo minio.ObjectInfo, err error) {
Expand Down

0 comments on commit 12b67e4

Please sign in to comment.