From da1b64f76af8e5110832cb0d76df166e44619a06 Mon Sep 17 00:00:00 2001 From: Benjy Weinberger Date: Fri, 13 Dec 2024 15:36:24 -0800 Subject: [PATCH] Ensure that the PEX_ROOT is always a realpath. (#2626) In almost all codepaths, a `pex_root` will be a realpath. See, e.g., https://github.com/pex-tool/pex/blob/06b8850f35ae67377ad2fe31d62ee1f71ba61eea/pex/pex_info.py#L511 https://github.com/pex-tool/pex/blob/06b8850f35ae67377ad2fe31d62ee1f71ba61eea/pex/variables.py#L320 However there was one codepath by which a non-realpath could be obtained, namely `boot()` calling`Variables.PEX_ROOT.value_or()` with a `raw_pex_root` given as the fallback value. This change ensures that `Variables.PEX_ROOT` is always a realpath. This manifested as a bug at pex boot time in the presence of a symlinked cache dir: https://github.com/pantsbuild/pants/issues/21321 --- pex/variables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pex/variables.py b/pex/variables.py index e14b7351a..dd536abf4 100644 --- a/pex/variables.py +++ b/pex/variables.py @@ -660,7 +660,7 @@ def PEX_ROOT(self): @PEX_ROOT.validator def _ensure_writeable_pex_root(self, raw_pex_root): - pex_root = os.path.expanduser(raw_pex_root) + pex_root = os.path.realpath(os.path.expanduser(raw_pex_root)) if not can_write_dir(pex_root): tmp_root = os.path.realpath(safe_mkdtemp()) pex_warnings.warn(