From: Daan De Meyer Date: Mon, 20 Jan 2025 10:37:38 +0000 (+0100) Subject: Use $HOME in current_home_dir() regardless of whether we're in it or not X-Git-Tag: v25~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=11005c46f6796d1f75ae033314d0ec4caaff796b;p=thirdparty%2Fmkosi.git Use $HOME in current_home_dir() regardless of whether we're in it or not If $HOME is set, let's always use it as a fallback if we're not running from a home directory. --- diff --git a/mkosi/util.py b/mkosi/util.py index 248d8e0cc..9b6d7e377 100644 --- a/mkosi/util.py +++ b/mkosi/util.py @@ -238,21 +238,20 @@ def groupby(seq: Sequence[T], key: Callable[[T], S]) -> list[tuple[S, list[T]]]: def current_home_dir() -> Optional[Path]: + home = Path(h) if (h := os.getenv("HOME")) else None + if Path.cwd() in (Path("/"), Path("/home")): - return None + return home if Path.cwd().is_relative_to("/root"): return Path("/root") - if (home := os.getenv("HOME")) and Path.cwd().is_relative_to(home): - return Path(home) - if Path.cwd().is_relative_to("/home"): # `Path.parents` only supports slices and negative indexing from Python 3.10 onwards. # TODO: Remove list() when we depend on Python 3.10 or newer. return list(Path.cwd().parents)[-3] - return None + return home def unique(seq: Sequence[T]) -> list[T]: