objectstore: yield Object not path from .new()

Instead of just returning the path of the temporary object that is
created in .new() the actual instance of the new `Object` is being
returned, which can then provide a richer interface for clients
than a plain directory path.
This commit is contained in:
Christian Kellner 2020-02-17 13:29:28 +01:00 committed by Tom Gundersen
parent 52736169f1
commit d10537da42
3 changed files with 16 additions and 16 deletions

View file

@ -105,11 +105,11 @@ class ObjectStore:
@contextlib.contextmanager
def new(self, object_id, base_id=None):
"""Creates a new directory for `object_id`.
"""Creates a new `Object` for `object_id`.
This method must be used as a context manager. It returns a path to a
temporary directory and only commits it when the context completes
without raising an exception.
This method must be used as a context manager. It returns a new
temporary instance of `Object`. It will only be committed to the
store if the context completes without raising an exception.
"""
with tempfile.TemporaryDirectory(dir=self.store) as tmp:
# the object that is yielded will be added to the content store
@ -122,7 +122,7 @@ class ObjectStore:
# fs supports it
obj.init(self.resolve_ref(base_id))
yield obj.path
yield obj
# if the yield above raises an exception, the working tree
# is cleaned up by tempfile, otherwise, the it the content

View file

@ -272,7 +272,7 @@ class Pipeline:
try:
with object_store.new(self.tree_id, base_id=base) as tree:
for stage in self.stages[base_idx + 1:]:
r = stage.run(tree,
r = stage.run(tree.path,
self.runner,
build_tree,
store,
@ -281,7 +281,7 @@ class Pipeline:
var=store,
secrets=secrets)
if stage.checkpoint:
object_store.snapshot(tree, stage.id)
object_store.snapshot(tree.path, stage.id)
results["stages"].append(r.as_dict())
except BuildError as err:
results["stages"].append(err.as_dict())
@ -298,7 +298,7 @@ class Pipeline:
r = self.assembler.run(tree,
self.runner,
build_tree,
output_dir=output_dir,
output_dir=output_dir.path,
interactive=interactive,
libdir=libdir,
var=store)