Avoid incorrectly returning errors when upload length is deferred

This commit is contained in:
Adam Jensen 2018-04-23 17:16:28 -04:00
parent 64c02a9de1
commit 5252c98cd7
2 changed files with 10 additions and 8 deletions

View File

@ -271,12 +271,14 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
return bytesUploaded, nil
}
if (size - offset) <= optimalPartSize {
if (size - offset) != n {
if !info.SizeIsDeferred {
if (size - offset) <= optimalPartSize {
if (size - offset) != n {
return bytesUploaded, nil
}
} else if n < optimalPartSize {
return bytesUploaded, nil
}
} else if n < optimalPartSize {
return bytesUploaded, nil
}
// Seek to the beginning of the file

View File

@ -333,7 +333,7 @@ func (handler *UnroutedHandler) PostFile(w http.ResponseWriter, r *http.Request)
handler.sendError(w, r, err)
return
}
} else if size == 0 {
} else if !sizeIsDeferred && size == 0 {
// Directly finish the upload if the upload is empty (i.e. has a size of 0).
// This statement is in an else-if block to avoid causing duplicate calls
// to finishUploadIfComplete if an upload is empty and contains a chunk.
@ -450,7 +450,7 @@ func (handler *UnroutedHandler) PatchFile(w http.ResponseWriter, r *http.Request
}
// Do not proxy the call to the data store if the upload is already completed
if info.Offset == info.Size {
if !info.SizeIsDeferred && info.Offset == info.Size {
w.Header().Set("Upload-Offset", strconv.FormatInt(offset, 10))
handler.sendResp(w, r, http.StatusNoContent)
return
@ -484,7 +484,7 @@ func (handler *UnroutedHandler) writeChunk(id string, info FileInfo, w http.Resp
offset := info.Offset
// Test if this upload fits into the file's size
if offset+length > info.Size {
if !info.SizeIsDeferred && offset+length > info.Size {
return ErrSizeExceeded
}
@ -531,7 +531,7 @@ func (handler *UnroutedHandler) writeChunk(id string, info FileInfo, w http.Resp
// function and send the necessary message on the CompleteUpload channel.
func (handler *UnroutedHandler) finishUploadIfComplete(info FileInfo) error {
// If the upload is completed, ...
if info.Offset == info.Size {
if !info.SizeIsDeferred && info.Offset == info.Size {
// ... allow custom mechanism to finish and cleanup the upload
if handler.composer.UsesFinisher {
if err := handler.composer.Finisher.FinishUpload(info.ID); err != nil {