Skip to content

Commit

Permalink
Return error if previous part is missing (#1017)
Browse files Browse the repository at this point in the history
Closes #1015.
  • Loading branch information
roman-khimov authored Oct 28, 2024
2 parents a618c92 + 968ea3a commit eb5b934
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/layer/multipart_upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,11 @@ func (n *layer) uploadPart(ctx context.Context, multipartInfo *data.MultipartInf
return nil, fmt.Errorf("getLastPart: %w", err)
}

// The previous part is not uploaded yet.
if lastPart == nil {
return nil, s3errors.GetAPIError(s3errors.ErrOperationAborted)
}

// try to restore hash state from the last part.
// the required interface is guaranteed according to the docs, so just cast without checks.
binaryUnmarshaler := multipartHash.(encoding.BinaryUnmarshaler)
Expand Down
7 changes: 7 additions & 0 deletions api/s3errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ const (
ErrEvaluatorBindingDoesNotExist
ErrMissingHeaders
ErrInvalidColumnIndex
ErrOperationAborted

ErrPostPolicyConditionInvalidFormat

Expand Down Expand Up @@ -1682,6 +1683,12 @@ var errorCodes = errorCodeMap{
Description: "Part number must be an integer between 1 and 10000, inclusive",
HTTPStatusCode: http.StatusBadRequest,
},
ErrOperationAborted: {
ErrCode: ErrOperationAborted,
Code: "OperationAborted",
Description: "A conflicting conditional operation is currently in progress against this resource. Try again.",
HTTPStatusCode: http.StatusConflict,
},
// Add your error structure here.
}

Expand Down

0 comments on commit eb5b934

Please sign in to comment.