]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Handle builds that run from directories with less than two parent dirs
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 18 Jan 2024 19:40:20 +0000 (20:40 +0100)
committerJörg Behrmann <behrmann@physik.fu-berlin.de>
Thu, 18 Jan 2024 22:23:07 +0000 (23:23 +0100)
Fixes #2302

mkosi/sandbox.py

index 555981b89a9f5a74d7fd0c527e7a69b50c02ead8..6bb19adddbb7e388b5672e7eabc29c5e8602243c 100644 (file)
@@ -119,9 +119,16 @@ def sandbox_cmd(
             if Path(d).exists():
                 cmdline += ["--bind", d, d]
 
-        # `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.
-        if (d := os.fspath(list(Path.cwd().parents)[-2])) not in (*dirs, "/home", "/usr", "/nix", "/tmp"):
+        if len(Path.cwd().parents) >= 2:
+            # `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.
+            d = os.fspath(list(Path.cwd().parents)[-2])
+        elif len(Path.cwd().parents) == 1:
+            d = os.fspath(Path.cwd())
+        else:
+            d = ""
+
+        if d and d not in (*dirs, "/home", "/usr", "/nix", "/tmp"):
             cmdline += ["--bind", d, d]
 
     if vartmp: