From fc42131bb6acaa9d474930add14f9e7fdf055bf5 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 14 Mar 2020 20:55:11 +0100 Subject: [PATCH] Fix dependency solving during image removal --- usr/bin/spoc-image | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/usr/bin/spoc-image b/usr/bin/spoc-image index ed04c76..2420b55 100755 --- a/usr/bin/spoc-image +++ b/usr/bin/spoc-image @@ -47,15 +47,18 @@ def download(image_name): def delete(image_name): # Remove the image including all images that have it as one of its parents # Check if image is in use - used = [c for c,d in repo_local.get_containers().items() if image_name in d['layers']] - if used: - sys.exit(f'Error: Image {image_name} is used by container{"s" if len(used) > 1 else ""} {", ".join(used)}') + used_by = [c for c,d in repo_local.get_containers().items() if image_name in d['layers']] + if used_by: + sys.exit(f'Error: Image {image_name} is used by container{"s" if len(used_by) > 1 else ""} {", ".join(used_by)}') + used_images = set() + for definition in repo_local.get_containers().values(): + used_images.update(definition['layers']) # Build dependency tree to safely remove the images in order of dependency depsolver = DepSolver() for image,definition in repo_local.get_images().items(): if image_name in definition['layers']: image = Image(image) - depsolver.add(image.name, image.layers, image) + depsolver.add(image.name, set(image.layers) - used_images, image) # Enqueue and run the removal actions queue = ActionQueue() for image in reversed(depsolver.solve()): @@ -65,14 +68,14 @@ def delete(image_name): @locked(LOCK_FILE, print_lock) def clean(): # Remove images which aren't used in any locally defined containers - used = set() + used_images = set() for definition in repo_local.get_containers().values(): - used.update(definition['layers']) + used_images.update(definition['layers']) # Build dependency tree to safely remove the images in order of dependency depsolver = DepSolver() - for image in set(repo_local.get_images()) - used: + for image in set(repo_local.get_images()) - used_images: image = Image(image) - depsolver.add(image.name, image.layers, image) + depsolver.add(image.name, set(image.layers) - used_images, image) # Enqueue and run the removal actions queue = ActionQueue() for image in reversed(depsolver.solve()):