Merge pull request #1056 from coreos-inc/dont-hide-ioerror

Handle IOErrors in v2 uploads
This commit is contained in:
Silas Sewell 2015-12-14 14:46:46 -05:00
commit 881fd53714
6 changed files with 63 additions and 42 deletions

View file

@ -124,8 +124,10 @@ def start_blob_upload(namespace, repo_name):
return accepted
else:
# The user plans to send us the entire body right now
uploaded = _upload_chunk(namespace, repo_name, new_upload_uuid)
uploaded, error = _upload_chunk(namespace, repo_name, new_upload_uuid)
uploaded.save()
if error:
_range_not_satisfiable(uploaded.byte_count)
return _finish_upload(namespace, repo_name, uploaded, digest)
@ -219,16 +221,16 @@ def _upload_chunk(namespace, repo_name, upload_uuid):
input_fp = wrap_with_handler(input_fp, found.sha_state.update)
try:
length_written, new_metadata = storage.stream_upload_chunk(location_set, upload_uuid,
start_offset, length, input_fp,
found.storage_metadata,
content_type=BLOB_CONTENT_TYPE)
length_written, new_metadata, error = storage.stream_upload_chunk(location_set, upload_uuid,
start_offset, length, input_fp,
found.storage_metadata,
content_type=BLOB_CONTENT_TYPE)
except InvalidChunkException:
_range_not_satisfiable(found.byte_count)
found.storage_metadata = new_metadata
found.byte_count += length_written
return found
return found, error
def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
@ -272,9 +274,12 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
@require_repo_write
@anon_protect
def upload_chunk(namespace, repo_name, upload_uuid):
upload = _upload_chunk(namespace, repo_name, upload_uuid)
upload, error = _upload_chunk(namespace, repo_name, upload_uuid)
upload.save()
if error:
_range_not_satisfiable(upload.byte_count)
accepted = make_response('', 204)
accepted.headers['Location'] = _current_request_path()
accepted.headers['Range'] = _render_range(upload.byte_count, with_bytes_prefix=False)
@ -291,7 +296,12 @@ def monolithic_upload_or_last_chunk(namespace, repo_name, upload_uuid):
if digest is None:
raise BlobUploadInvalid()
found = _upload_chunk(namespace, repo_name, upload_uuid)
found, error = _upload_chunk(namespace, repo_name, upload_uuid)
if error:
found.save()
_range_not_satisfiable(found.byte_count)
return _finish_upload(namespace, repo_name, found, digest)