objectstore: store object data within subfolder
Instead of storing the (tree) data directly at the root of the object specific directory, move it into a `data/tree` subfolder. This prepares for two things: 1) the `tree` folder will allow us to add another folder next to it to store metadata. 2) storing both, `tree` and the future metadata folder in a common subfolder, prepares for the future integration with the new caching layer (`FsCache`).
This commit is contained in:
parent
f04ea2bab2
commit
917c5bb2f5
2 changed files with 10 additions and 8 deletions
|
|
@ -18,7 +18,6 @@ __all__ = [
|
||||||
|
|
||||||
|
|
||||||
class Object:
|
class Object:
|
||||||
|
|
||||||
class Mode(enum.Enum):
|
class Mode(enum.Enum):
|
||||||
READ = 0
|
READ = 0
|
||||||
WRITE = 1
|
WRITE = 1
|
||||||
|
|
@ -32,12 +31,13 @@ class Object:
|
||||||
if self.mode == Object.Mode.READ:
|
if self.mode == Object.Mode.READ:
|
||||||
path = self.store.resolve_ref(uid)
|
path = self.store.resolve_ref(uid)
|
||||||
assert path is not None
|
assert path is not None
|
||||||
self._path = path
|
self._path = os.path.join(path, "data")
|
||||||
else:
|
else:
|
||||||
workdir = self.tempdir("workdir")
|
workdir = self.tempdir("workdir")
|
||||||
self._path = os.path.join(workdir.name, "object")
|
|
||||||
os.makedirs(self._path)
|
|
||||||
self._workdir = workdir
|
self._workdir = workdir
|
||||||
|
self._path = os.path.join(workdir.name, "data")
|
||||||
|
tree = os.path.join(self._path, "tree")
|
||||||
|
os.makedirs(tree)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self) -> Optional[str]:
|
def id(self) -> Optional[str]:
|
||||||
|
|
@ -54,7 +54,7 @@ class Object:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def tree(self) -> str:
|
def tree(self) -> str:
|
||||||
return self._path
|
return os.path.join(self._path, "tree")
|
||||||
|
|
||||||
def store_tree(self):
|
def store_tree(self):
|
||||||
"""Store the tree with a fresh name and close it
|
"""Store the tree with a fresh name and close it
|
||||||
|
|
@ -68,7 +68,9 @@ class Object:
|
||||||
|
|
||||||
name = str(uuid.uuid4())
|
name = str(uuid.uuid4())
|
||||||
|
|
||||||
destination = os.path.join(self.store.objects, name)
|
base = os.path.join(self.store.objects, name)
|
||||||
|
os.makedirs(base)
|
||||||
|
destination = os.path.join(base, "data")
|
||||||
os.rename(self._path, destination)
|
os.rename(self._path, destination)
|
||||||
self._path = destination
|
self._path = destination
|
||||||
|
|
||||||
|
|
@ -90,7 +92,7 @@ class Object:
|
||||||
# manually remove the tree, it might contain
|
# manually remove the tree, it might contain
|
||||||
# files with immutable flag set, which will
|
# files with immutable flag set, which will
|
||||||
# throw off standard Python 3 tempdir cleanup
|
# throw off standard Python 3 tempdir cleanup
|
||||||
rmrf.rmtree(os.path.join(workdir.name, "object"))
|
rmrf.rmtree(os.path.join(workdir.name, "data"))
|
||||||
|
|
||||||
workdir.cleanup()
|
workdir.cleanup()
|
||||||
self._workdir = None
|
self._workdir = None
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def store_path(store: objectstore.ObjectStore, ref: str, path: str) -> bool:
|
||||||
obj = store.resolve_ref(ref)
|
obj = store.resolve_ref(ref)
|
||||||
if not obj or not os.path.exists(obj):
|
if not obj or not os.path.exists(obj):
|
||||||
return False
|
return False
|
||||||
return os.path.exists(os.path.join(obj, path))
|
return os.path.exists(os.path.join(obj, "data", "tree", path))
|
||||||
|
|
||||||
|
|
||||||
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
@unittest.skipUnless(test.TestBase.can_bind_mount(), "root-only")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue