Checkpoint implementing PATCH according to Docker
This commit is contained in:
parent
35919b4cc8
commit
8269d4ac90
4 changed files with 223 additions and 59 deletions
|
@ -14,7 +14,7 @@ from endpoints.v2.errors import BlobUnknown, BlobUploadInvalid, BlobUploadUnknow
|
|||
from auth.jwt_auth import process_jwt_auth
|
||||
from endpoints.decorators import anon_protect
|
||||
from util.cache import cache_control
|
||||
from util.registry.filelike import wrap_with_handler
|
||||
from util.registry.filelike import wrap_with_handler, StreamSlice
|
||||
from storage.basestorage import InvalidChunkException
|
||||
|
||||
|
||||
|
@ -201,7 +201,15 @@ def _upload_chunk(namespace, repo_name, upload_uuid):
|
|||
except _InvalidRangeHeader:
|
||||
_range_not_satisfiable(found.byte_count)
|
||||
|
||||
if start_offset > 0 and start_offset > found.byte_count:
|
||||
_range_not_satisfiable(found.byte_count)
|
||||
|
||||
input_fp = get_input_stream(request)
|
||||
if start_offset > 0 and start_offset < found.byte_count:
|
||||
# Skip the bytes which were received on a previous push, which are already stored and
|
||||
# included in the sha calculation
|
||||
input_fp = StreamSlice(input_fp, found.byte_count - start_offset)
|
||||
|
||||
input_fp = wrap_with_handler(input_fp, found.sha_state.update)
|
||||
|
||||
try:
|
||||
|
@ -222,10 +230,21 @@ def _finish_upload(namespace, repo_name, upload_obj, expected_digest):
|
|||
if not digest_tools.digests_equal(computed_digest, expected_digest):
|
||||
raise BlobUploadInvalid()
|
||||
|
||||
# Mark the blob as uploaded.
|
||||
# Move the storage into place, or if this was a re-upload, cancel it
|
||||
final_blob_location = digest_tools.content_path(expected_digest)
|
||||
storage.complete_chunked_upload({upload_obj.location.name}, upload_obj.uuid, final_blob_location,
|
||||
|
||||
if storage.exists({upload_obj.location.name}, final_blob_location):
|
||||
# It already existed, clean up our upload which served as proof that we had the file
|
||||
storage.cancel_chunked_upload({upload_obj.location.name}, upload_obj.uuid,
|
||||
upload_obj.storage_metadata)
|
||||
|
||||
else:
|
||||
# We were the first ones to upload this image (at least to this location)
|
||||
# Let's copy it into place
|
||||
storage.complete_chunked_upload({upload_obj.location.name}, upload_obj.uuid,
|
||||
final_blob_location, upload_obj.storage_metadata)
|
||||
|
||||
# Mark the blob as uploaded.
|
||||
model.blob.store_blob_record_and_temp_link(namespace, repo_name, expected_digest,
|
||||
upload_obj.location, upload_obj.byte_count,
|
||||
app.config['PUSH_TEMP_TAG_EXPIRATION_SEC'])
|
||||
|
|
Reference in a new issue