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:
Christian Kellner 2022-11-23 23:56:09 +01:00
parent f04ea2bab2
commit 917c5bb2f5
2 changed files with 10 additions and 8 deletions

View file

@ -18,7 +18,6 @@ __all__ = [
class Object:
class Mode(enum.Enum):
READ = 0
WRITE = 1
@ -32,12 +31,13 @@ class Object:
if self.mode == Object.Mode.READ:
path = self.store.resolve_ref(uid)
assert path is not None
self._path = path
self._path = os.path.join(path, "data")
else:
workdir = self.tempdir("workdir")
self._path = os.path.join(workdir.name, "object")
os.makedirs(self._path)
self._workdir = workdir
self._path = os.path.join(workdir.name, "data")
tree = os.path.join(self._path, "tree")
os.makedirs(tree)
@property
def id(self) -> Optional[str]:
@ -54,7 +54,7 @@ class Object:
@property
def tree(self) -> str:
return self._path
return os.path.join(self._path, "tree")
def store_tree(self):
"""Store the tree with a fresh name and close it
@ -68,7 +68,9 @@ class Object:
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)
self._path = destination
@ -90,7 +92,7 @@ class Object:
# manually remove the tree, it might contain
# files with immutable flag set, which will
# 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()
self._workdir = None

View file

@ -20,7 +20,7 @@ def store_path(store: objectstore.ObjectStore, ref: str, path: str) -> bool:
obj = store.resolve_ref(ref)
if not obj or not os.path.exists(obj):
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")