diff --git a/libmamba/src/api/configuration.cpp b/libmamba/src/api/configuration.cpp index 946992aaf6..8ca6778c5d 100644 --- a/libmamba/src/api/configuration.cpp +++ b/libmamba/src/api/configuration.cpp @@ -965,13 +965,18 @@ namespace mamba } } - std::vector fallback_envs_dirs_hook(const Context& context) + void envs_dirs_hook(const Context& context, std::vector& dirs) { - return { context.prefix_params.root_prefix / "envs" }; - } + // Check that "root_prefix/envs" is already in the dirs, + // and append if not - to match `conda` + // Therefore, there is no need for a fallback value anymore + fs::u8path default_env_dir = context.prefix_params.root_prefix / "envs"; + if (std::find(dirs.begin(), dirs.end(), default_env_dir) == dirs.end()) + { + dirs.push_back(default_env_dir); + } - void envs_dirs_hook(std::vector& dirs) - { + // Check that the values exist as directories for (auto& d : dirs) { d = fs::weakly_canonical(util::expand_home(d.string())).string(); @@ -1297,10 +1302,10 @@ namespace mamba .set_rc_configurable(RCConfigLevel::kHomeDir) .set_env_var_names({ "CONDA_ENVS_DIRS" }) .needs({ "root_prefix" }) - .set_fallback_value_hook( - [this] { return detail::fallback_envs_dirs_hook(m_context); } + .set_post_merge_hook( + [this](decltype(m_context.envs_dirs)& value) + { return detail::envs_dirs_hook(m_context, value); } ) - .set_post_merge_hook(detail::envs_dirs_hook) .description("Possible locations of named environments")); insert(Configurable("pkgs_dirs", &m_context.pkgs_dirs) diff --git a/libmamba/tests/src/core/test_configuration.cpp b/libmamba/tests/src/core/test_configuration.cpp index 82bbf7629e..6b92848fd1 100644 --- a/libmamba/tests/src/core/test_configuration.cpp +++ b/libmamba/tests/src/core/test_configuration.cpp @@ -538,6 +538,40 @@ namespace mamba - https://repo.mamba.pm/conda-forge)")); } + TEST_CASE_METHOD(Configuration, "envs_dirs") + { + // Load default config + // `envs_dirs` should be set to `root_prefix / envs` + config.load(); + + const auto& envs_dirs = config.at("envs_dirs").value>(); + REQUIRE(envs_dirs.size() == 1); + REQUIRE( + envs_dirs[0] + == util::path_concat( + std::string(config.at("root_prefix").value()), + "envs" + ) + ); + } + + TEST_CASE_METHOD(Configuration, "envs_dirs_with_additional_rc") + { + std::string cache1 = util::path_concat(util::user_home_dir(), "foo_envs_dirs"); + std::string rc1 = "envs_dirs:\n - " + cache1; + + load_test_config(rc1); + + REQUIRE( + config.dump() + == "envs_dirs:\n - " + cache1 + "\n - " + + util::path_concat( + std::string(config.at("root_prefix").value()), + "envs" + ) + ); + } + TEST_CASE_METHOD(Configuration, "pkgs_dirs") { std::string cache1 = util::path_concat(util::user_home_dir(), "foo"); diff --git a/micromamba/src/common_options.hpp b/micromamba/src/common_options.hpp index 40c4a3f4f2..1449d2da6d 100644 --- a/micromamba/src/common_options.hpp +++ b/micromamba/src/common_options.hpp @@ -40,9 +40,6 @@ init_channel_parser(CLI::App* subcom, mamba::Configuration& config); void load_channel_options(mamba::Context& ctx); -void -channels_hook(std::vector& channels); - void override_channels_hook(mamba::Configuration& config, bool& override_channels);