From f7bcec60f4ac53e95396d78a718e5da840719f06 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 17 Dec 2020 16:46:40 +0100 Subject: [PATCH] objectstore: make objects identifyable This adds a new `id` property to the ObjectStore.Object, that is meant to reflect the identifer of the Stage to build the contents of it. This will help to transparently access objects that have been built but not committed to the store. Setting the `base_id` of an object will also set its `id`. When the object is then modified via write() the `id` will be set to None, since no the content and the id are out of sync. In the same way, restting an object will reset its `id` to None. --- osbuild/objectstore.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py index 3d8e17bb..2f4909a4 100644 --- a/osbuild/objectstore.py +++ b/osbuild/objectstore.py @@ -49,6 +49,7 @@ class Object: self._base = None self._workdir = None self._tree = None + self.id = None self.store = store self.reset() @@ -72,6 +73,7 @@ class Object: def base(self, base_id: Optional[str]): self._init = not base_id self._base = base_id + self.id = base_id @property def treesum(self) -> str: @@ -97,6 +99,7 @@ class Object: self._check_readers() self._check_writer() self.init() + self.id = None with self.tempdir("writer") as target: mount(self._path, target, ro=False) try: @@ -153,6 +156,7 @@ class Object: if self._workdir: self._workdir.cleanup() self._workdir = None + self.id = None def _check_readers(self): """Internal: Raise a ValueError if there are readers"""