From 56e0ac7c92247f73b3fc369fb433f7b74579ffae Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Sat, 21 Mar 2020 13:20:26 +0100 Subject: [PATCH] pipeline: eagerly cleanup trees in error case The `build_stages` method short-circuits and returns early in case any of the stages fail to build and returns None for the tree, and build tree, therefore both of those can immediately cleaned up at that point. For this add a small helper `cleanup` that will call the cleanup method for all supplied arguments, after filtering out None values. --- osbuild/pipeline.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 620c6f6e..2465e5a2 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -17,6 +17,11 @@ RESET = "\033[0m" BOLD = "\033[1m" +def cleanup(*objs): + """Call cleanup method for all objects, filters None values out""" + _ = map(lambda o: o.cleanup(), filter(None, objs)) + + class BuildResult: def __init__(self, origin, returncode, output): self.name = origin.name @@ -285,6 +290,7 @@ class Pipeline: results["stages"].append(r.as_dict()) if not r.success: + cleanup(build_tree, tree) results["success"] = False return results, None, None