Actually delete the image data when deleting the tag.
This commit is contained in:
parent
b584d74bf0
commit
518cd1be85
4 changed files with 19 additions and 14 deletions
|
@ -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)
|
||||
|
|
Reference in a new issue