Get tag deletion working

This commit is contained in:
Joseph Schorr 2014-01-07 15:21:24 -05:00
parent 9da93c7caf
commit 971dd7dd3a
2 changed files with 47 additions and 2 deletions

View file

@ -741,8 +741,48 @@ def list_repository_tags(namespace_name, repository_name):
Repository.namespace == namespace_name)
def delete_tag_and_images(namespace_name, repository_name, tag_name):
# TODO: Implement this.
pass
all_images = get_repository_images(namespace_name, repository_name)
all_tags = list_repository_tags(namespace_name, repository_name)
# Find the tag's information.
found_tag = None
for tag in all_tags:
if tag.name == tag_name:
found_tag = tag
break
if not found_tag:
return
# Build the set of database IDs corresponding to the tag's ancestor images, as well as the
# tag's image itself.
tag_image_ids = set(found_tag.image.ancestors.split('/'))
tag_image_ids.add(str(found_tag.image.id))
# Filter out any images that belong to any other tags.
for tag in all_tags:
if tag.name != tag_name:
# Remove all ancestors of the tag.
tag_image_ids = tag_image_ids - set(tag.image.ancestors.split('/'))
# Remove the current image ID.
tag_image_ids.discard(str(tag.image.id))
# Find all the images that belong to the tag.
tag_images = []
for image in all_images:
if str(image.id) in tag_image_ids:
tag_images.append(image)
# Delete the tag found.
found_tag.delete_instance()
# Delete the images found.
for image in tag_images:
image.delete_instance()
# TODO: Delete the image's layer data as well.
def get_tag_image(namespace_name, repository_name, tag_name):
joined = Image.select().join(RepositoryTag).join(Repository)

View file

@ -250,6 +250,11 @@ function RepoCtrl($scope, Restangular, ApiService, $routeParams, $rootScope, $lo
$location.search('tag', $scope.currentTag.name);
}
}
if ($scope.currentTag && !repo.tags[$scope.currentTag.name]) {
$scope.currentTag = null;
$scope.currentImage = null;
}
};
$scope.getTagCount = function(repo) {