diff --git a/data/model.py b/data/model.py index 7c4f80fb5..e0cef7ddb 100644 --- a/data/model.py +++ b/data/model.py @@ -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) diff --git a/static/js/controllers.js b/static/js/controllers.js index c58dd564a..800d25232 100644 --- a/static/js/controllers.js +++ b/static/js/controllers.js @@ -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) {