From daa2e1c3bb7d97137bfb506f9682a727820ab1ad Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 19 Aug 2022 18:15:41 +0200 Subject: [PATCH] objectstore: option to clone object on commit Add a new `clone` parameter to the `commit` method on `ObjectStore` that when used will clone the object to the store instead of using the `store_tree` method which moves the object and resets it. This is the first step of removing copy-on-write support from `Object`. --- osbuild/objectstore.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py index 46d7e393..f2f8c6b9 100644 --- a/osbuild/objectstore.py +++ b/osbuild/objectstore.py @@ -308,7 +308,7 @@ class ObjectStore(contextlib.AbstractContextManager): return obj - def commit(self, obj: Object, object_id: str) -> str: + def commit(self, obj: Object, object_id: str, clone: bool = False) -> str: """Commits a Object to the object store Move the contents of the obj (Object) to object directory @@ -323,7 +323,11 @@ class ObjectStore(contextlib.AbstractContextManager): # The object is stored in the objects directory using its unique # name. This means that each commit will always result in a new # object in the store, even if an identical one exists. - object_name = obj.store_tree() + if clone: + object_name = str(uuid.uuid4()) + obj.clone(os.path.join(self.objects, object_name)) + else: + object_name = obj.store_tree() # symlink the object_id (config hash) in the refs directory to the # object name in the objects directory. If a symlink by that name