Fix missing CompleteMultipartUpload Etag. (#3227)

Fixes #3224
This commit is contained in:
Harshavardhana 2016-11-10 07:41:02 -08:00 committed by GitHub
parent 2f373684f5
commit 51d1e6f75b
8 changed files with 17 additions and 8 deletions

View File

@ -660,7 +660,7 @@ func (fs fsObjects) CompleteMultipartUpload(bucket string, object string, upload
defer appendPathLock.Unlock()
// Calculate s3 compatible md5sum for complete multipart.
s3MD5, err := getCompleteMultipartMD5(parts...)
s3MD5, err := getCompleteMultipartMD5(parts)
if err != nil {
return "", err
}

View File

@ -1864,7 +1864,7 @@ func testObjectCompleteMultipartUpload(obj ObjectLayer, instanceType string, t T
},
},
}
s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts...)
s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts)
if err != nil {
t.Fatalf("Obtaining S3MD5 failed")
}

View File

@ -877,7 +877,6 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
}
md5Sum, err = objectAPI.CompleteMultipartUpload(bucket, object, uploadID, completeParts)
if err != nil {
err = errorCause(err)
errorIf(err, "Unable to complete multipart upload.")
@ -903,6 +902,9 @@ func (api objectAPIHandlers) CompleteMultipartUploadHandler(w http.ResponseWrite
return
}
// Set etag.
w.Header().Set("ETag", "\""+md5Sum+"\"")
// Write success response.
w.Write(encodedSuccessResponse)
w.(http.Flusher).Flush()

View File

@ -1507,7 +1507,7 @@ func testAPICompleteMultipartHandler(obj ObjectLayer, instanceType, bucketName s
}
// on successful complete multipart operation the s3MD5 for the parts uploaded will be returned.
s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts...)
s3MD5, err := getCompleteMultipartMD5(inputParts[3].parts)
if err != nil {
t.Fatalf("Obtaining S3MD5 failed")
}

View File

@ -141,7 +141,7 @@ func getUUID() (uuidStr string) {
}
// Create an s3 compatible MD5sum for complete multipart transaction.
func getCompleteMultipartMD5(parts ...completePart) (string, error) {
func getCompleteMultipartMD5(parts []completePart) (string, error) {
var finalMD5Bytes []byte
for _, part := range parts {
md5Bytes, err := hex.DecodeString(part.ETag)

View File

@ -158,7 +158,7 @@ func TestGetCompleteMultipartMD5(t *testing.T) {
}
for i, test := range testCases {
result, err := getCompleteMultipartMD5(test.parts...)
result, err := getCompleteMultipartMD5(test.parts)
if result != test.expectedResult {
t.Fatalf("test %d failed: expected: result=%v, got=%v", i+1, test.expectedResult, result)
}

View File

@ -2503,5 +2503,12 @@ func (s *TestSuiteCommon) TestObjectMultipart(c *C) {
c.Assert(err, IsNil)
// verify whether complete multipart was successful.
c.Assert(response.StatusCode, Equals, http.StatusOK)
var parts []completePart
for _, part := range completeUploads.Parts {
part.ETag = strings.Trim(part.ETag, "\"")
parts = append(parts, part)
}
etag, err := getCompleteMultipartMD5(parts)
c.Assert(err, IsNil)
c.Assert(strings.Trim(response.Header.Get("Etag"), "\""), Equals, etag)
}

View File

@ -664,7 +664,7 @@ func (xl xlObjects) CompleteMultipartUpload(bucket string, object string, upload
return "", traceError(InvalidUploadID{UploadID: uploadID})
}
// Calculate s3 compatible md5sum for complete multipart.
s3MD5, err := getCompleteMultipartMD5(parts...)
s3MD5, err := getCompleteMultipartMD5(parts)
if err != nil {
return "", err
}