]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Use $HOME in current_home_dir() regardless of whether we're in it or not
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Jan 2025 10:37:38 +0000 (11:37 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 20 Jan 2025 13:08:56 +0000 (14:08 +0100)
If $HOME is set, let's always use it as a fallback if we're not running
from a home directory.

mkosi/util.py

index 248d8e0ccc566c17ae3cc6dd9f2607752a259ddc..9b6d7e377e1c005904afb5ce89fed016fcb0e391 100644 (file)
@@ -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]: