]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Improve home directory detection
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 25 Mar 2024 10:20:58 +0000 (11:20 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 25 Mar 2024 10:50:37 +0000 (11:50 +0100)
If we're invoked as root from a home directory, always use that as
the user's home directory instead of trying to detect it ourselves, this
makes sure we use the right home directory even when we're invoked in a
user namespace.

mkosi/user.py

index 4437fd5e71b6be4a2a5fad581e7b482af5878855..c7c5c27103e259832f732f2fbdc3198c7765e3f3 100644 (file)
@@ -44,6 +44,9 @@ class INVOKING_USER:
     @classmethod
     @functools.lru_cache(maxsize=1)
     def home(cls) -> Path:
+        if cls.invoked_as_root and Path.cwd().is_relative_to("/home") and len(Path.cwd().parents) > 2:
+            return list(Path.cwd().parents)[-3]
+
         return Path(f"~{cls.name()}").expanduser()
 
     @classmethod