Correct when S3Store write loop is ended

This commit is contained in:
Marius 2017-03-23 12:06:15 +01:00
parent 7f26757a40
commit d48e4ac577
1 changed files with 7 additions and 2 deletions

View File

@ -248,9 +248,14 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
limitedReader := io.LimitReader(src, store.MaxPartSize) limitedReader := io.LimitReader(src, store.MaxPartSize)
n, err := io.Copy(file, limitedReader) n, err := io.Copy(file, limitedReader)
if err != nil && err != io.EOF { // io.Copy does not return io.EOF, so we not have to handle it differently.
if err != nil {
return bytesUploaded, err return bytesUploaded, err
} }
// If io.Copy is finished reading, it will always return (0, nil).
if n == 0 {
return bytesUploaded, nil
}
if (size - offset) <= store.MinPartSize { if (size - offset) <= store.MinPartSize {
if (size - offset) != n { if (size - offset) != n {
@ -274,7 +279,7 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
return bytesUploaded, err return bytesUploaded, err
} }
offset += bytesUploaded offset += n
bytesUploaded += n bytesUploaded += n
nextPartNum += 1 nextPartNum += 1
} }