Fix deletion of labels and add tests

This commit is contained in:
Joseph Schorr 2016-08-26 16:07:49 -04:00
parent b3c592c09a
commit 1a2666be07
4 changed files with 151 additions and 105 deletions

View file

@ -152,19 +152,22 @@ def garbage_collect_tags(repo):
num_deleted_manifests = 0
if len(manifests_to_delete) > 0:
# Find the set of IDs for all the labels to delete.
labels = list(TagManifestLabel
.select(TagManifestLabel.id)
.where(TagManifestLabel.annotated << manifests_to_delete))
manifest_labels_query = (TagManifestLabel
.select()
.where(TagManifestLabel.repository == repo,
TagManifestLabel.annotated << manifests_to_delete))
if len(labels) > 0:
# Delete the mapping entries.
label_ids = [manifest_label.label_id for manifest_label in manifest_labels_query]
if label_ids:
# Delete all the mapping entries.
(TagManifestLabel
.delete()
.where(TagManifestLabel.annotated << manifests_to_delete)
.where(TagManifestLabel.repository == repo,
TagManifestLabel.annotated << manifests_to_delete)
.execute())
# Delete the labels themselves.
Label.delete().where(Label.id << [label.id for label in labels]).execute()
# Delete all the matching labels.
Label.delete().where(Label.id << label_ids).execute()
# Delete the tag manifests themselves.
num_deleted_manifests = (TagManifest