]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Don't use .cache if HOME=/
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 29 Jul 2024 17:57:53 +0000 (19:57 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 29 Jul 2024 18:49:30 +0000 (20:49 +0200)
If the user's home directory is /, don't use .cache but use /var/cache
instead.

mkosi/user.py

index b9267034415381acc4715712ffd316bd3415b2d1..8a37f675a72bf01e1f0ecbed14a7043eed6ea5e2 100644 (file)
@@ -77,7 +77,11 @@ class INVOKING_USER:
     def cache_dir(cls) -> Path:
         if (env := os.getenv("XDG_CACHE_HOME")) or (env := os.getenv("CACHE_DIRECTORY")):
             cache = Path(env)
-        elif cls.is_regular_user() and (Path.cwd().is_relative_to(INVOKING_USER.home()) or not cls.invoked_as_root):
+        elif (
+            cls.is_regular_user() and
+            INVOKING_USER.home() != Path("/") and
+            (Path.cwd().is_relative_to(INVOKING_USER.home()) or not cls.invoked_as_root)
+        ):
             cache = INVOKING_USER.home() / ".cache"
         else:
             cache = Path("/var/cache")