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.
This commit is contained in:
Christian Kellner 2020-12-17 16:46:40 +01:00 committed by Tom Gundersen
parent a8783761a1
commit f7bcec60f4

View file

@ -49,6 +49,7 @@ class Object:
self._base = None self._base = None
self._workdir = None self._workdir = None
self._tree = None self._tree = None
self.id = None
self.store = store self.store = store
self.reset() self.reset()
@ -72,6 +73,7 @@ class Object:
def base(self, base_id: Optional[str]): def base(self, base_id: Optional[str]):
self._init = not base_id self._init = not base_id
self._base = base_id self._base = base_id
self.id = base_id
@property @property
def treesum(self) -> str: def treesum(self) -> str:
@ -97,6 +99,7 @@ class Object:
self._check_readers() self._check_readers()
self._check_writer() self._check_writer()
self.init() self.init()
self.id = None
with self.tempdir("writer") as target: with self.tempdir("writer") as target:
mount(self._path, target, ro=False) mount(self._path, target, ro=False)
try: try:
@ -153,6 +156,7 @@ class Object:
if self._workdir: if self._workdir:
self._workdir.cleanup() self._workdir.cleanup()
self._workdir = None self._workdir = None
self.id = None
def _check_readers(self): def _check_readers(self):
"""Internal: Raise a ValueError if there are readers""" """Internal: Raise a ValueError if there are readers"""