diff --git a/scripts/meta/env/load.sh b/scripts/meta/env/load.sh index 1de27c5e2b..dfb67daf3a 100755 --- a/scripts/meta/env/load.sh +++ b/scripts/meta/env/load.sh @@ -62,7 +62,8 @@ fi _infinito_env_source="${_infinito_env_dotenv}" _infinito_env_scratch="" -if [[ -f "${_infinito_env_dotenv}" && -n "${INFINITO_DISTRO:-}" && "${INFINITO_DISTRO}" != "$(sed -n 's/^INFINITO_DISTRO=//p' "${_infinito_env_dotenv}")" ]]; then +_infinito_env_distro="${INFINITO_DISTRO:-}" +if [[ -f "${_infinito_env_dotenv}" && -n "${_infinito_env_distro}" && "${_infinito_env_distro}" != "$(sed -n 's/^INFINITO_DISTRO=//p' "${_infinito_env_dotenv}")" ]]; then _infinito_env_scratch="$(mktemp -d)" _infinito_env_source="${_infinito_env_scratch}/env" fi @@ -98,7 +99,7 @@ set +a if [[ -n "${_infinito_env_scratch}" ]]; then rm -rf "${_infinito_env_scratch}" fi -unset _infinito_env_source _infinito_env_scratch +unset _infinito_env_source _infinito_env_scratch _infinito_env_distro for _infinito_env_key in "${!_infinito_env_preserved[@]}"; do declare -gx "${_infinito_env_key}=${_infinito_env_preserved[${_infinito_env_key}]}" diff --git a/tests/unit/python/scripts/meta/env/test_load.py b/tests/unit/python/scripts/meta/env/test_load.py index af61434b78..1fa719719d 100644 --- a/tests/unit/python/scripts/meta/env/test_load.py +++ b/tests/unit/python/scripts/meta/env/test_load.py @@ -8,6 +8,7 @@ stay as it was. from __future__ import annotations +import filecmp import os import shutil import subprocess @@ -93,9 +94,13 @@ class TestDistroDerivedKeys(unittest.TestCase): shutil.copy(LOADER_DIR / name, checkout / "scripts" / "meta" / "env") dotenv = checkout / ".env" shutil.copy(self.scratch / "debian.env", dotenv) - before = dotenv.read_bytes() - shown = bash(f"load() {{ source scripts/meta/env/load.sh; }}\n{steps}", checkout) - self.assertEqual(dotenv.read_bytes(), before, ".env was rewritten") + shown = bash( + f"load() {{ source scripts/meta/env/load.sh; }}\n{steps}", checkout + ) + self.assertTrue( + filecmp.cmp(dotenv, self.scratch / "debian.env", shallow=False), + ".env was rewritten", + ) return shown def test_the_two_distros_derive_different_keys(self):