From 2d78a0bbea9a48349d14d25db461dcf20641e508 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 5 May 2022 11:19:49 +0200 Subject: [PATCH] pipeline: separate object creation from access Check for existing checkpoint in `Pipeline.build_stages` by trying to get the object, instead of just checking for its existence. Later, if no checkpoints were found, i.e. `tree` is `None`, create a new object. This avoids mixing of new object creation and object access. --- osbuild/pipeline.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/osbuild/pipeline.py b/osbuild/pipeline.py index 702722b6..95721f54 100644 --- a/osbuild/pipeline.py +++ b/osbuild/pipeline.py @@ -299,14 +299,17 @@ class Pipeline: # Not in the store yet, need to actually build it, but maybe # an intermediate checkpoint exists: Find the last stage that # already exists in the store and use that as the base. - tree = object_store.new() + tree = None todo = collections.deque() for stage in reversed(self.stages): - if object_store.contains(stage.id): - tree.base = stage.id + tree = object_store.get(stage.id) + if tree: break todo.append(stage) # append right side of the deque + if not tree: + tree = object_store.new() + # If two run() calls race each-other, two trees will get built # and it is nondeterministic which of them will end up # referenced by the `tree_id` in the content store if they are