Skip to content

Commit

Permalink
Distinguish between root prefix and default root prefix
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Jerphanion <[email protected]>
  • Loading branch information
jjerphan committed Jan 23, 2025
1 parent e6a8053 commit 0466f31
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libmamba/include/mamba/api/configuration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ namespace mamba

namespace detail
{
auto get_default_root_prefix(fs::u8path& prefix) -> void;
auto get_root_prefix() -> fs::u8path;

template <class T>
bool ConfigurableImpl<T>::cli_configured() const
Expand Down
12 changes: 11 additions & 1 deletion libmamba/src/api/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand Down
3 changes: 2 additions & 1 deletion libmamba/src/core/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>

#include "mamba/api/configuration.hpp"
#include "mamba/core/context.hpp"
#include "mamba/core/execution.hpp"
#include "mamba/core/output.hpp"
Expand Down Expand Up @@ -177,7 +178,7 @@ namespace mamba
Context::Context(const ContextOptions& options)
{
on_ci = static_cast<bool>(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" };
Expand Down
3 changes: 1 addition & 2 deletions libmamba/src/download/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down
4 changes: 2 additions & 2 deletions libmamba/tests/src/download/test_downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <catch2/catch_all.hpp>

#include "mamba/api/configuration.hpp"
#include "mamba/download/downloader.hpp"

#include "mambatests.hpp"
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 0466f31

Please sign in to comment.