Handle IOErrors in v2 uploads
This commit is contained in:
parent
35437c9f55
commit
2dcc1f13a6
6 changed files with 63 additions and 42 deletions
|
@ -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)
|
||||
|
||||
|
@ -210,16 +212,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):
|
||||
|
@ -263,9 +265,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)
|
||||
|
@ -282,7 +287,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)
|
||||
|
||||
|
||||
|
|
Reference in a new issue