From a8b4f80dbda0098e0b910ebd29608fd658402d12 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sat, 3 Sep 2016 06:38:32 -0700 Subject: [PATCH] putObject: Streaming uploads with size -1 should avoid fetching previous partsInfo. size == -1 should be treated specially for putObjectStream() and avoid fetching partsInfo for previously uploaded parts since '-1' has no guarantee that the data has no changed. Let the client upload again and not resume for unknown sizes. Fixes - https://github.com/minio/mc/issues/1819 --- api-put-object-multipart.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/api-put-object-multipart.go b/api-put-object-multipart.go index 463185b080..9677684510 100644 --- a/api-put-object-multipart.go +++ b/api-put-object-multipart.go @@ -94,8 +94,9 @@ func (c Client) putObjectMultipartStream(bucketName, objectName string, reader i } // If This session is a continuation of a previous session fetch all - // previously uploaded parts info. - if !isNew { + // previously uploaded parts info and as a special case only fetch partsInfo + // for only known upload size. + if !isNew && size > -1 { // Fetch previously uploaded parts and maximum part size. partsInfo, err = c.listObjectParts(bucketName, objectName, uploadID) if err != nil { @@ -190,7 +191,12 @@ func (c Client) putObjectMultipartStream(bucketName, objectName string, reader i for i := 1; i <= totalPartsCount; i++ { part, ok := partsInfo[i] if !ok { - return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", i)) + // Error our only if we know exactly the right amount of part sizes. + if size > -1 { + return 0, ErrInvalidArgument(fmt.Sprintf("Missing part number %d", i)) + } + // Breakout an finish the upload if size is -1. + break } complMultipartUpload.Parts = append(complMultipartUpload.Parts, completePart{ ETag: part.ETag,