Fix force push causing duplicated entries

This commit is contained in:
Antoine Legrand 2017-03-25 23:07:13 +01:00
parent 7b411b2c25
commit d2ed37e158
3 changed files with 23 additions and 6 deletions

View file

@ -33,7 +33,11 @@ def get_app_release(repo, tag_name, media_type):
def delete_app_release(repo, tag_name, media_type):
""" Delete a Tag/media-type couple """
""" Terminate a Tag/media-type couple
It find the corresponding tag/manifest and remove from the manifestlistmanifest the manifest
1. it terminates the current tag (in all-cases)
2. if the new manifestlist is not empty, it creates a new tag for it
"""
media_type_id = ManifestListManifest.media_type.get_id(manifest_media_type(media_type))
with db_transaction():
@ -65,7 +69,7 @@ def delete_app_release(repo, tag_name, media_type):
return tag
def create_app_release(repo, tag_name, manifest, digest, force=False):
def create_app_release(repo, tag_name, manifest_data, digest, force=False):
""" Create a new application release, it includes creating a new Tag, ManifestList,
ManifestListManifests, Manifest, ManifestBlob.
@ -74,7 +78,7 @@ def create_app_release(repo, tag_name, manifest, digest, force=False):
"""
with db_transaction():
# Create/get the package manifest
manifest = manifest_model.get_or_create_manifest(manifest, manifest['mediaType'])
manifest = manifest_model.get_or_create_manifest(manifest_data, manifest_data['mediaType'])
# get the tag
tag = tag_model.get_or_initialize_tag(repo, tag_name)
@ -86,6 +90,7 @@ def create_app_release(repo, tag_name, manifest, digest, force=False):
elif tag_model.tag_media_type_exists(tag, manifest.media_type):
if force:
delete_app_release(repo, tag_name, manifest.media_type.name)
return create_app_release(repo, tag_name, manifest_data, digest, force=False)
else:
raise PackageAlreadyExists("package exists already")