From 5fbf5bb43184087dbadca2282547d9be9fd33892 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Thu, 5 Mar 2020 18:46:58 +0100 Subject: [PATCH] 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. --- osbuild/objectstore.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/osbuild/objectstore.py b/osbuild/objectstore.py index 05013f6c..d4312285 100644 --- a/osbuild/objectstore.py +++ b/osbuild/objectstore.py @@ -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)