diff --git a/libmamba/include/mamba/api/configuration.hpp b/libmamba/include/mamba/api/configuration.hpp index aa8aeaa84f..7d37ee7406 100644 --- a/libmamba/include/mamba/api/configuration.hpp +++ b/libmamba/include/mamba/api/configuration.hpp @@ -483,7 +483,7 @@ namespace mamba namespace detail { - auto get_default_root_prefix(fs::u8path& prefix) -> void; + auto get_root_prefix() -> fs::u8path; template bool ConfigurableImpl::cli_configured() const diff --git a/libmamba/src/api/configuration.cpp b/libmamba/src/api/configuration.cpp index c2b8acb16a..e7fd2e5400 100644 --- a/libmamba/src/api/configuration.cpp +++ b/libmamba/src/api/configuration.cpp @@ -751,13 +751,23 @@ namespace mamba } } + auto get_root_prefix() -> fs::u8path + { + fs::u8path root_prefix = util::get_env("MAMBA_ROOT_PREFIX").value_or(""); + if (root_prefix.empty()) + { + get_default_root_prefix(root_prefix); + } + return root_prefix; + } + void root_prefix_hook(Configuration& config, fs::u8path& prefix) { auto& env_name = config.at("env_name"); if (prefix.empty()) { - get_default_root_prefix(prefix); + prefix = get_root_prefix(); if (env_name.configured()) { diff --git a/libmamba/src/core/context.cpp b/libmamba/src/core/context.cpp index e58ad01b27..e436c59f97 100644 --- a/libmamba/src/core/context.cpp +++ b/libmamba/src/core/context.cpp @@ -12,6 +12,7 @@ #include #include +#include "mamba/api/configuration.hpp" #include "mamba/core/context.hpp" #include "mamba/core/execution.hpp" #include "mamba/core/output.hpp" @@ -177,7 +178,7 @@ namespace mamba Context::Context(const ContextOptions& options) { on_ci = static_cast(util::get_env("CI")); - prefix_params.root_prefix = util::get_env("MAMBA_ROOT_PREFIX").value_or(""); + prefix_params.root_prefix = detail::get_root_prefix(); prefix_params.conda_prefix = prefix_params.root_prefix; envs_dirs = { prefix_params.root_prefix / "envs" }; diff --git a/libmamba/src/download/downloader.cpp b/libmamba/src/download/downloader.cpp index c7801b65bc..6f905fe68e 100644 --- a/libmamba/src/download/downloader.cpp +++ b/libmamba/src/download/downloader.cpp @@ -88,8 +88,7 @@ namespace mamba::download // root prefix or the system CA certificates if the certificate is not present. fs::u8path libmamba_library_path; - fs::u8path root_prefix; - detail::get_default_root_prefix(root_prefix); + fs::u8path root_prefix = detail::get_root_prefix(); fs::u8path env_prefix_conda_cert = root_prefix / "ssl" / "cacert.pem"; LOG_INFO << "Checking for CA certificates at the root prefix: " diff --git a/libmamba/tests/src/download/test_downloader.cpp b/libmamba/tests/src/download/test_downloader.cpp index 2a37e7a63a..e5d0977cb5 100644 --- a/libmamba/tests/src/download/test_downloader.cpp +++ b/libmamba/tests/src/download/test_downloader.cpp @@ -6,6 +6,7 @@ #include +#include "mamba/api/configuration.hpp" #include "mamba/download/downloader.hpp" #include "mambatests.hpp" @@ -78,9 +79,8 @@ namespace mamba download::MultiResult res = download::download(dl_request, context.mirrors, context); REQUIRE(context.remote_fetch_params.curl_initialized); - // Check that the path is correct auto certificates = context.remote_fetch_params.ssl_verify; - const fs::u8path root_prefix = context.prefix_params.root_prefix; + const fs::u8path root_prefix = detail::get_root_prefix(); auto expected_certificates = root_prefix / "ssl" / "cacert.pem"; REQUIRE(certificates == expected_certificates); }