From 59f11d170753412c16942268e54b0e5c77a12db7 Mon Sep 17 00:00:00 2001 From: Anis Elleuch Date: Thu, 9 Mar 2017 22:47:17 +0100 Subject: [PATCH] Revert hashCopyN simplification fix Partially revert https://github.com/minio/minio-go/pull/614 --- api-put-object-common.go | 2 +- api-put-object-multipart.go | 2 +- api-put-object.go | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api-put-object-common.go b/api-put-object-common.go index 3384d7b2d..5f5f568e6 100644 --- a/api-put-object-common.go +++ b/api-put-object-common.go @@ -161,7 +161,7 @@ func hashCopyN(hashAlgorithms map[string]hash.Hash, hashSums map[string][]byte, for k, v := range hashAlgorithms { hashSums[k] = v.Sum(nil) } - return size, nil + return size, err } // getUploadID - fetch upload id if already present for an object name diff --git a/api-put-object-multipart.go b/api-put-object-multipart.go index e29220365..a62d4075d 100644 --- a/api-put-object-multipart.go +++ b/api-put-object-multipart.go @@ -113,7 +113,7 @@ func (c Client) putObjectMultipartStream(bucketName, objectName string, reader i // Calculates hash sums while copying partSize bytes into tmpBuffer. prtSize, rErr := hashCopyN(hashAlgos, hashSums, tmpBuffer, reader, partSize) - if rErr != nil { + if rErr != nil && rErr != io.EOF { return 0, rErr } diff --git a/api-put-object.go b/api-put-object.go index 4a6781b65..ac974ac9a 100644 --- a/api-put-object.go +++ b/api-put-object.go @@ -209,9 +209,6 @@ func (c Client) putObjectSingle(bucketName, objectName string, reader io.Reader, // Initialize a new temporary buffer. tmpBuffer := new(bytes.Buffer) size, err = hashCopyN(hashAlgos, hashSums, tmpBuffer, reader, size) - if err != nil { - return 0, err - } reader = bytes.NewReader(tmpBuffer.Bytes()) tmpBuffer.Reset() } else { @@ -232,7 +229,10 @@ func (c Client) putObjectSingle(bucketName, objectName string, reader io.Reader, } reader = tmpFile } - + // Return error if its not io.EOF. + if err != nil && err != io.EOF { + return 0, err + } // Execute put object. st, err := c.putObjectDo(bucketName, objectName, reader, hashSums["md5"], hashSums["sha256"], size, metaData) if err != nil {