From: Daan De Meyer Date: Thu, 18 Jan 2024 19:40:20 +0000 (+0100) Subject: Handle builds that run from directories with less than two parent dirs X-Git-Tag: v20.2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb33d8f5784358e5f95ae449d20bed9e414ccd5f;p=thirdparty%2Fmkosi.git Handle builds that run from directories with less than two parent dirs Fixes #2302 --- diff --git a/mkosi/sandbox.py b/mkosi/sandbox.py index 555981b89..6bb19addd 100644 --- a/mkosi/sandbox.py +++ b/mkosi/sandbox.py @@ -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: