From 59e4896dbfa0ee0149068a722043f63f8347b32b Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Sat, 16 Feb 2019 12:40:53 -0500 Subject: [PATCH] Make absolutely sure we don't overwrite an existing storage checksum Old V1 code would occasionally do so, which was never correct, but we never hit it because we didn't (practically) share storage rows before. Now that we explicitly do, we were occasionally de-checksum-ing storage rows on V1 pushes (which are extremely rare as-is). This change makes sure we don't do that, and makes sure we always set a proper digest and checksum on storage rows. --- data/model/blob.py | 6 ++++++ data/model/image.py | 3 --- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/data/model/blob.py b/data/model/blob.py index e97badedf..cc90cea2f 100644 --- a/data/model/blob.py +++ b/data/model/blob.py @@ -52,6 +52,8 @@ def store_blob_record_and_temp_link(namespace, repo_name, blob_digest, location_ link_expiration_s, uncompressed_byte_count=None): """ Store a record of the blob and temporarily link it to the specified repository. """ + assert blob_digest + with db_transaction(): try: storage = ImageStorage.get(content_checksum=blob_digest) @@ -183,6 +185,10 @@ def get_or_create_shared_blob(digest, byte_data, storage): accessible, such as the special empty gzipped tar layer that Docker no longer pushes to us. """ + assert digest + assert byte_data is not None + assert storage + try: return ImageStorage.get(content_checksum=digest, uploading=False) except ImageStorage.DoesNotExist: diff --git a/data/model/image.py b/data/model/image.py index 08d6cfa2d..8c437e3fc 100644 --- a/data/model/image.py +++ b/data/model/image.py @@ -341,9 +341,6 @@ def set_image_metadata(docker_image_id, namespace_name, repository_name, created # We cleanup any old checksum in case it's a retry after a fail fetched.v1_checksum = None - fetched.storage.content_checksum = None - fetched.storage.save() - fetched.comment = comment fetched.command = command fetched.v1_json_metadata = v1_json_metadata