From 581ec4779811e52e20a4951727adf52609d888ba Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Mon, 27 Aug 2018 15:02:03 -0400 Subject: [PATCH] Handle the cases where an existing tag manifest or manifest has already been created --- data/model/tag.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/data/model/tag.py b/data/model/tag.py index dbff7ff73..d4c89c153 100644 --- a/data/model/tag.py +++ b/data/model/tag.py @@ -612,7 +612,13 @@ def get_possibly_expired_tag(namespace, repo_name, tag_name): def associate_generated_tag_manifest(namespace, repo_name, tag_name, manifest, storage_id_map): tag = get_active_tag(namespace, repo_name, tag_name) - return _create_manifest(tag, manifest, storage_id_map) + try: + manifest = TagManifest.get(digest=manifest.digest) + manifest.tag = tag + manifest.save() + return manifest, False + except TagManifest.DoesNotExist: + return _create_manifest(tag, manifest, storage_id_map), True def _create_manifest(tag, manifest, storage_id_map): @@ -639,9 +645,20 @@ def _create_manifest(tag, manifest, storage_id_map): def populate_manifest(repository, manifest, legacy_image, storage_ids): """ Populates the rows for the manifest, including its blobs and legacy image. """ media_type = Manifest.media_type.get_id(manifest.media_type) + + # Check for an existing manifest. If present, return it. + try: + return Manifest.get(repository=repository, digest=manifest.digest) + except Manifest.DoesNotExist: + pass + with db_transaction(): - manifest_row = Manifest.create(digest=manifest.digest, repository=repository, - manifest_bytes=manifest.bytes, media_type=media_type) + try: + manifest_row = Manifest.create(digest=manifest.digest, repository=repository, + manifest_bytes=manifest.bytes, media_type=media_type) + except IntegrityError: + return Manifest.get(repository=repository, digest=manifest.digest) + ManifestLegacyImage.create(manifest=manifest_row, repository=repository, image=legacy_image) blobs_to_insert = [dict(manifest=manifest_row, repository=repository,