upload/oci: fix a crash when the uploader returns an empty response

resp.IsResumable crashes if resp.MultipartUploadResponse == nil. This happens
for instance when authentication fails. Fix this by also checking the
MultipartUploadResponse field.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2023-08-29 14:48:51 +02:00 committed by Ondřej Budai
parent d6eacad494
commit 23718dc707

View file

@ -77,7 +77,9 @@ func (c Client) uploadToBucket(objectName string, bucketName string, namespace s
ctx := context.Background()
resp, err := uploadManager.UploadFile(ctx, req)
if err != nil {
if resp.IsResumable() {
// resp.IsResumable crashes if resp.MultipartUploadResponse == nil
// Thus, we need to check for both.
if resp.MultipartUploadResponse != nil && resp.IsResumable() {
resp, err = uploadManager.ResumeUploadFile(ctx, *resp.MultipartUploadResponse.UploadID)
if err != nil {
return err