diff --git a/buildstream/_frontend/cli.py b/buildstream/_frontend/cli.py index 835d700c536c19a92d73a94c0fb4ddf8d660cb4c..d3c3eadefbb183f465e43546ea7d90d1dd075068 100644 --- a/buildstream/_frontend/cli.py +++ b/buildstream/_frontend/cli.py @@ -1100,13 +1100,19 @@ def artifact_delete(app, artifacts): if element is not None: elements = [element] + # Remove specified elements and artifacts if elements: elements = app.stream.load_selection(elements, selection=PipelineSelection.NONE) for element in elements: - cache.remove(cache.get_artifact_fullname(element, element._get_cache_key())) + cache_key = element._get_cache_key() + ref = cache.get_artifact_fullname(element, cache_key) + cache.remove(ref, defer_prune=True) if artifacts: - for i, ref in enumerate(artifacts, start=1): - cache.remove(ref, defer_prune=False) + for ref in artifacts: + cache.remove(ref, defer_prune=True) + + # Now we've removed all the refs, prune the unreachable objects + cache.prune() ##################################################################