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,6 +271,7 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
return bytesUploaded, nil return bytesUploaded, nil
} }
if !info.SizeIsDeferred {
if (size - offset) <= optimalPartSize { if (size - offset) <= optimalPartSize {
if (size - offset) != n { if (size - offset) != n {
return bytesUploaded, nil return bytesUploaded, nil
@ -278,6 +279,7 @@ func (store S3Store) WriteChunk(id string, offset int64, src io.Reader) (int64,
} else if n < optimalPartSize { } else if n < optimalPartSize {
return bytesUploaded, nil return bytesUploaded, nil
} }
}
// Seek to the beginning of the file // Seek to the beginning of the file
file.Seek(0, 0) file.Seek(0, 0)

View File

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