From: Daan De Meyer Date: Mon, 25 Mar 2024 10:20:58 +0000 (+0100) Subject: Improve home directory detection X-Git-Tag: v23~65^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7cd9b2e2bb7ec9eba9c32750e21f957d00efa7eb;p=thirdparty%2Fmkosi.git Improve home directory detection 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. --- diff --git a/mkosi/user.py b/mkosi/user.py index 4437fd5e7..c7c5c2710 100644 --- a/mkosi/user.py +++ b/mkosi/user.py @@ -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