objectstore: use 'tmp' subdir for temp directories

Instead of creating temporary directories at the root of the store
create them in a sub-directory called 'tmp'. This should make it
easy to cleanup left-over (temporary) dirs in case of crashes.
Additionally, it has the nice side effect that it is possible to
check that there are no objects that are still in-flight, i.e. not
cleaned-up.
This commit is contained in:
Christian Kellner 2020-03-05 18:46:58 +01:00 committed by Tom Gundersen
parent 01d989e718
commit 5fbf5bb431

View file

@ -207,9 +207,11 @@ class ObjectStore:
self.store = store
self.objects = f"{store}/objects"
self.refs = f"{store}/refs"
self.tmp = f"{store}/tmp"
os.makedirs(self.store, exist_ok=True)
os.makedirs(self.objects, exist_ok=True)
os.makedirs(self.refs, exist_ok=True)
os.makedirs(self.tmp, exist_ok=True)
def contains(self, object_id):
if not object_id:
@ -224,7 +226,7 @@ class ObjectStore:
def tempdir(self, prefix=None, suffix=None):
"""Return a tempfile.TemporaryDirectory within the store"""
return tempfile.TemporaryDirectory(dir=self.store,
return tempfile.TemporaryDirectory(dir=self.tmp,
prefix=prefix,
suffix=suffix)