Fix the garbage collect method to remove unused old images.

This commit is contained in:
jakedt 2014-02-17 14:38:35 -05:00
parent e7064f1191
commit 7428d2aa50

View file

@ -1011,15 +1011,19 @@ def garbage_collect_repository(namespace_name, repository_name):
uuids_to_check_for_gc = set()
for image_id_to_remove in to_remove:
image_to_remove = all_images[image_id_to_remove]
image_to_remove.delete_instance()
if not image_to_remove.storage:
if not image_to_remove.storage or not image_to_remove.storage.id:
image_path = store.image_path(namespace_name, repository_name,
image_to_remove.docker_image_id, None)
logger.debug('Deleting image storage: %s', image_path)
store.remove(image_path)
else:
logger.debug('Adding image storage to the gc list: %s',
image_to_remove.storage.uuid)
uuids_to_check_for_gc.add(image_to_remove.storage.uuid)
image_to_remove.delete_instance()
storage_to_remove = (ImageStorage
.select()
.join(Image, JOIN_LEFT_OUTER)
@ -1139,7 +1143,7 @@ def delete_all_repository_tags(namespace_name, repository_name):
except Repository.DoesNotExist:
raise DataModelException('Invalid repository \'%s/%s\'' %
(namespace_name, repository_name))
RepositoryTag.delete().where(RepositoryTag.repository == repo).execute()
RepositoryTag.delete().where(RepositoryTag.repository == repo.id).execute()
def __entity_permission_repo_query(entity_id, entity_table,