objectstore: Object keeps reference to store

Keep are reference to the parent store, which this object is tied
to. It is currently not yet used directly but is a preparation for
a closer Object and ObjectStore integration that will happen in
commits to follow.
This commit is contained in:
Christian Kellner 2020-02-26 14:09:18 +01:00 committed by Tom Gundersen
parent 19f49e5dc3
commit 52736169f1

View file

@ -28,7 +28,8 @@ def suppress_oserror(*errnos):
class Object:
def __init__(self, path: str):
def __init__(self, store: "ObjectStore", path: str):
self.store = store
os.makedirs(path, mode=0o755, exist_ok=True)
self.path = path
@ -113,7 +114,7 @@ class ObjectStore:
with tempfile.TemporaryDirectory(dir=self.store) as tmp:
# the object that is yielded will be added to the content store
# on success as object_id
obj = Object(f"{tmp}/tree")
obj = Object(self, f"{tmp}/tree")
if base_id:
# the base, the working tree and the output dir are all
@ -143,7 +144,7 @@ class ObjectStore:
# the latter with the contents of `object_path` and commit
# it to the store
with tempfile.TemporaryDirectory(dir=self.store) as tmp:
obj = Object(f"{tmp}/tree")
obj = Object(self, f"{tmp}/tree")
obj.init(object_path)
return self.commit(obj, object_id)