diff --git a/libmamba/include/mamba/api/configuration.hpp b/libmamba/include/mamba/api/configuration.hpp index 6d1d9ccf52..aa8aeaa84f 100644 --- a/libmamba/include/mamba/api/configuration.hpp +++ b/libmamba/include/mamba/api/configuration.hpp @@ -483,6 +483,8 @@ namespace mamba namespace detail { + auto get_default_root_prefix(fs::u8path& prefix) -> void; + template bool ConfigurableImpl::cli_configured() const { diff --git a/libmamba/src/api/configuration.cpp b/libmamba/src/api/configuration.cpp index 435433bb88..478ae095aa 100644 --- a/libmamba/src/api/configuration.cpp +++ b/libmamba/src/api/configuration.cpp @@ -713,22 +713,42 @@ namespace mamba return { fs::weakly_canonical(std::move(prefix)) }; } - /** - * In mamba 1.0, only micromamba was using this location. - */ - auto default_root_prefix_v1() -> fs::u8path + auto get_default_root_prefix(fs::u8path& prefix) -> void { - return fs::u8path(util::user_home_dir()) / "micromamba"; - } - - /** - * In mamba 2.0, we change the default location. - * We unconditionally name the subfolder "mamba" for compatibility between ``mamba`` - * and ``micromamba``, as well as consistency with ``MAMBA_`` environment variables. - */ - auto default_root_prefix_v2() -> fs::u8path - { - return fs::u8path(util::user_data_dir()) / "mamba"; + if (util::get_env("MAMBA_DEFAULT_ROOT_PREFIX")) + { + prefix = util::get_env("MAMBA_DEFAULT_ROOT_PREFIX").value(); + LOG_WARNING << unindent(R"( + 'MAMBA_DEFAULT_ROOT_PREFIX' is meant for testing purpose. + Consider using 'MAMBA_ROOT_PREFIX' instead)"); + } + else + { +#ifdef MAMBA_USE_INSTALL_PREFIX_AS_BASE + // mamba case + // set the root prefix as the mamba installation path + get_root_prefix_from_mamba_bin(util::which("mamba")) + .transform([&](fs::u8path&& p) { prefix = std::move(p); }) + .or_else([](mamba_error&& error) { throw std::move(error); }); +#else + // micromamba case + + // In 1.0, only micromamba was using this location. + const fs::u8path default_root_prefix_v1 = fs::u8path(util::user_home_dir()) + / "micromamba"; + + // In 2.0, we change the default location. + // We unconditionally name the subfolder "mamba" for compatibility between ``mamba`` + // and ``micromamba``, as well as consistency with ``MAMBA_`` environment variables. + const fs::u8path default_root_prefix_v2 = fs::u8path(util::user_data_dir()) / "mamba"; + + validate_existing_root_prefix(default_root_prefix_v1) + .or_else([](const auto& /* error */) + { return validate_root_prefix(default_root_prefix_v2); }) + .transform([&](fs::u8path&& p) { prefix = std::move(p); }) + .or_else([](mamba_error&& error) { throw std::move(error); }); +#endif + } } void root_prefix_hook(Configuration& config, fs::u8path& prefix) @@ -737,30 +757,7 @@ namespace mamba if (prefix.empty()) { - if (util::get_env("MAMBA_DEFAULT_ROOT_PREFIX")) - { - prefix = util::get_env("MAMBA_DEFAULT_ROOT_PREFIX").value(); - LOG_WARNING << unindent(R"( - 'MAMBA_DEFAULT_ROOT_PREFIX' is meant for testing purpose. - Consider using 'MAMBA_ROOT_PREFIX' instead)"); - } - else - { -#ifdef MAMBA_USE_INSTALL_PREFIX_AS_BASE - // mamba case - // set the root prefix as the mamba installation path - get_root_prefix_from_mamba_bin(util::which("mamba")) - .transform([&](fs::u8path&& p) { prefix = std::move(p); }) - .or_else([](mamba_error&& error) { throw std::move(error); }); -#else - // micromamba case - validate_existing_root_prefix(default_root_prefix_v1()) - .or_else([](const auto& /* error */) - { return validate_root_prefix(default_root_prefix_v2()); }) - .transform([&](fs::u8path&& p) { prefix = std::move(p); }) - .or_else([](mamba_error&& error) { throw std::move(error); }); -#endif - } + get_default_root_prefix(prefix); if (env_name.configured()) { diff --git a/libmamba/src/download/downloader.cpp b/libmamba/src/download/downloader.cpp index 9da0597aad..1e1b83777a 100644 --- a/libmamba/src/download/downloader.cpp +++ b/libmamba/src/download/downloader.cpp @@ -4,6 +4,7 @@ // // The full license is in the file LICENSE, distributed with this software. +#include "mamba/api/configuration.hpp" #include "mamba/core/invoke.hpp" #include "mamba/core/thread_utils.hpp" #include "mamba/core/util.hpp" @@ -80,7 +81,8 @@ 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 = util::get_env("MAMBA_ROOT_PREFIX").value_or(""); + fs::u8path root_prefix; + detail::get_default_root_prefix(root_prefix); fs::u8path env_prefix_conda_cert = root_prefix / "ssl" / "cacert.pem"; LOG_INFO << "Checking for CA certificates at the root prefix: "