Actually delete the image data when deleting the tag.

This commit is contained in:
yackob03 2014-01-09 17:13:26 -05:00
parent b584d74bf0
commit 518cd1be85
4 changed files with 19 additions and 14 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)