]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use directory in user's home as output directory if possible
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 30 Jan 2025 12:38:03 +0000 (13:38 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 30 Jan 2025 14:15:44 +0000 (15:15 +0100)
Otherwise, if the user's home is on a separate partition, we have to
do a very expensive copy to /var/tmp.

tests/__init__.py

index eb3a5ad1dbc589ea646bc156fbcf00a559329097..6aa7596aef13edeab686a6cc47aef5e919e132a2 100644 (file)
@@ -17,6 +17,7 @@ from mkosi.distributions import Distribution
 from mkosi.run import CompletedProcess, fork_and_wait, run
 from mkosi.sandbox import acquire_privileges
 from mkosi.tree import rmtree
+from mkosi.user import INVOKING_USER
 from mkosi.util import _FILE, PathString
 
 
@@ -33,7 +34,12 @@ class Image:
         self.config = config
 
     def __enter__(self) -> "Image":
-        self.output_dir = Path(os.getenv("TMPDIR", "/var/tmp")) / uuid.uuid4().hex[:16]
+        if (cache := INVOKING_USER.cache_dir()) and os.access(cache, os.W_OK):
+            tmpdir = cache
+        else:
+            tmpdir = Path("/var/tmp")
+
+        self.output_dir = Path(os.getenv("TMPDIR", tmpdir)) / uuid.uuid4().hex[:16]
 
         return self