From e5b12e55f48815ffaaa827d5c38105540beab1bb Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 17 Dec 2020 16:52:00 +0100 Subject: [PATCH] objectstore: transparant access for floating objs A "floating" object is a temporary object that is identified, i.e. has an `id` and is thus also locked, but is not committed to the store. The `contains` and `get` methods of ObjectStore will now return such floating objects as if they were committed ones, provind transparent access to object that have been built during the exectuin of osbuild. --- osbuild/objectstore.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py index 2f4909a4..70d90ec1 100644 --- a/osbuild/objectstore.py +++ b/osbuild/objectstore.py @@ -251,9 +251,20 @@ class ObjectStore(contextlib.AbstractContextManager): os.makedirs(self.tmp, exist_ok=True) self._objs = weakref.WeakSet() + def _get_floating(self, object_id: str) -> Optional[Object]: + """Internal: get a non-committed object""" + for obj in self._objs: + if obj.id == object_id: + return obj + return None + def contains(self, object_id): if not object_id: return False + + if self._get_floating(object_id): + return True + return os.access(self.resolve_ref(object_id), os.F_OK) def resolve_ref(self, object_id: Optional[str]) -> Optional[str]: @@ -269,6 +280,10 @@ class ObjectStore(contextlib.AbstractContextManager): suffix=suffix) def get(self, object_id): + obj = self._get_floating(object_id) + if obj: + return obj + if not self.contains(object_id): return None