From 518cd1be85e15269dc907b3851c4c60940c3bb47 Mon Sep 17 00:00:00 2001 From: yackob03 Date: Thu, 9 Jan 2014 17:13:26 -0500 Subject: [PATCH] Actually delete the image data when deleting the tag. --- data/model.py | 19 +++++++++++++++---- endpoints/api.py | 2 -- endpoints/registry.py | 8 -------- storage/basestorage.py | 4 ++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/data/model.py b/data/model.py index 21b64e750..4087e5284 100644 --- a/data/model.py +++ b/data/model.py @@ -6,12 +6,14 @@ import operator import json from datetime import timedelta + from database import * from util.validation import * from util.names import format_robot_username logger = logging.getLogger(__name__) +store = app.config['STORAGE'] class DataModelException(Exception): @@ -769,8 +771,8 @@ def delete_tag_and_images(namespace_name, repository_name, tag_name): 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. + # 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)) @@ -784,7 +786,8 @@ def delete_tag_and_images(namespace_name, repository_name, tag_name): tag_image_ids.discard(str(tag.image.id)) # Find all the images that belong to the tag. - tag_images = [image for image in all_images if str(image.id) in tag_image_ids] + tag_images = [image for image in all_images + if str(image.id) in tag_image_ids] # Delete the tag found. found_tag.delete_instance() @@ -793,7 +796,10 @@ def delete_tag_and_images(namespace_name, repository_name, tag_name): for image in tag_images: image.delete_instance() - # TODO: Delete the image's layer data as well. + repository_path = store.image_path(namespace_name, repository_name, + image.docker_image_id) + logger.debug('Recursively deleting image path: %s' % repository_path) + store.remove(repository_path) def get_tag_image(namespace_name, repository_name, tag_name): @@ -992,6 +998,11 @@ def purge_repository(namespace_name, repository_name): Repository.namespace == namespace_name) fetched.delete_instance(recursive=True) + repository_path = store.repository_namespace_path(namespace_name, + repository_name) + logger.debug('Recursively deleting path: %s' % repository_path) + store.remove(repository_path) + def get_private_repo_count(username): joined = Repository.select().join(Visibility) diff --git a/endpoints/api.py b/endpoints/api.py index 234489f90..479efdb45 100644 --- a/endpoints/api.py +++ b/endpoints/api.py @@ -25,7 +25,6 @@ from auth.permissions import (ReadRepositoryPermission, AdministerOrganizationPermission, OrganizationMemberPermission, ViewTeamPermission) -from endpoints import registry from endpoints.common import common_login from util.cache import cache_control from datetime import datetime, timedelta @@ -872,7 +871,6 @@ def delete_repository(namespace, repository): permission = AdministerRepositoryPermission(namespace, repository) if permission.can(): model.purge_repository(namespace, repository) - registry.delete_repository_storage(namespace, repository) log_action('delete_repo', namespace, {'repo': repository, 'namespace': namespace}) return make_response('Deleted', 204) diff --git a/endpoints/registry.py b/endpoints/registry.py index 626dd171d..86a954d7c 100644 --- a/endpoints/registry.py +++ b/endpoints/registry.py @@ -343,14 +343,6 @@ def put_image_json(namespace, repository, image_id): return make_response('true', 200) -def delete_repository_storage(namespace, repository): - """ Caller should have already verified proper permissions. """ - repository_path = store.repository_namespace_path(namespace, repository) - - logger.debug('Recursively deleting path: %s' % repository_path) - store.remove(repository_path) - - def process_image_changes(namespace, repository, image_id): logger.debug('Generating diffs for image: %s' % image_id) diff --git a/storage/basestorage.py b/storage/basestorage.py index 94d1af659..1217e3c2b 100644 --- a/storage/basestorage.py +++ b/storage/basestorage.py @@ -34,6 +34,10 @@ class Storage(object): namespace, repository) + def image_path(self, namespace, repository, image_id): + return '{0}/{1}/{2}/{3}/'.format(self.images, namespace, repository, + image_id) + def image_json_path(self, namespace, repository, image_id): return '{0}/{1}/{2}/{3}/json'.format(self.images, namespace, repository, image_id)