Fix V1 push for layers already uploaded

This commit is contained in:
Joseph Schorr 2019-03-04 16:47:46 -05:00
parent 79a115b01d
commit bdae32630e
4 changed files with 35 additions and 10 deletions

View file

@ -55,16 +55,23 @@ def store_blob_record_and_temp_link(namespace, repo_name, blob_digest, location_
""" Store a record of the blob and temporarily link it to the specified repository.
"""
assert blob_digest
assert byte_count is not None
with db_transaction():
try:
storage = ImageStorage.get(content_checksum=blob_digest)
storage.image_size = byte_count
save_changes = False
if uncompressed_byte_count is not None:
if storage.image_size is None:
storage.image_size = byte_count
save_changes = True
if storage.uncompressed_size is None and uncompressed_byte_count is not None:
storage.uncompressed_size = uncompressed_byte_count
save_changes = True
storage.save()
if save_changes:
storage.save()
ImageStoragePlacement.get(storage=storage, location=location_obj)
except ImageStorage.DoesNotExist:

View file

@ -21,8 +21,10 @@ def test_store_blob(initialized_db):
blob_storage2 = model.blob.store_blob_record_and_temp_link(ADMIN_ACCESS_USER, REPO, digest,
location, 2048, 0, 6000)
assert blob_storage2.id == blob_storage.id
assert blob_storage2.image_size == 2048
assert blob_storage2.uncompressed_size == 6000
# The sizes should be unchanged.
assert blob_storage2.image_size == 1024
assert blob_storage2.uncompressed_size == 5000
# Add a new digest, ensure it has a new record.
otherdigest = 'anotherdigest'