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.
@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