Merge pull request #2476 from coreos-inc/fix_bug_force_push
Fix force push causing duplicated entries
This commit is contained in:
commit
024f73ecd4
3 changed files with 23 additions and 6 deletions
|
@ -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")
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ def create_or_update_tag(repo, tag_name, manifest_list=None, linked_tag=None, ta
|
|||
|
||||
def get_or_initialize_tag(repo, tag_name, tag_kind="release"):
|
||||
try:
|
||||
return Tag.select().where(Tag.repository == repo, Tag.name == tag_name).get()
|
||||
return tag_alive_oci(Tag.select().where(Tag.repository == repo, Tag.name == tag_name)).get()
|
||||
except Tag.DoesNotExist:
|
||||
return Tag(repo=repo, name=tag_name, tag_kind=Tag.tag_kind.get_id(tag_kind))
|
||||
|
||||
|
@ -85,5 +85,3 @@ def filter_tags_by_media_type(tag_query, media_type):
|
|||
.join(ManifestListManifest, on=(ManifestListManifest.manifest_list == Tag.manifest_list))
|
||||
.where(ManifestListManifest.media_type == ManifestListManifest.media_type.get_id(media_type)))
|
||||
return t
|
||||
|
||||
|
||||
|
|
|
@ -214,3 +214,17 @@ class TestQuayModels(CnrTestModels):
|
|||
p2.save()
|
||||
b2db = oci_blob.get_blob(p2.digest)
|
||||
assert b2db.id == bdb.id
|
||||
|
||||
def test_push_same_blob(self, db_with_data1):
|
||||
p = db_with_data1.Package.get("titi/rocketchat", "2.0.1", 'kpm')
|
||||
assert p.package == "titi/rocketchat"
|
||||
assert p.release == "2.0.1"
|
||||
assert p.digest == "d3b54b7912fe770a61b59ab612a442eac52a8a5d8d05dbe92bf8f212d68aaa80"
|
||||
blob = db_with_data1.Blob.get("titi/rocketchat",
|
||||
"72ed15c9a65961ecd034cca098ec18eb99002cd402824aae8a674a8ae41bd0ef")
|
||||
p2 = db_with_data1.Package("titi/rocketchat", "2.0.1", "kpm", blob)
|
||||
p2.save(force=True)
|
||||
pnew = db_with_data1.Package.get("titi/rocketchat", "2.0.1", 'kpm')
|
||||
assert pnew.package == "titi/rocketchat"
|
||||
assert pnew.release == "2.0.1"
|
||||
assert pnew.digest == "72ed15c9a65961ecd034cca098ec18eb99002cd402824aae8a674a8ae41bd0ef"
|
||||
|
|
Reference in a new issue