mirror of https://github.com/mamba-org/mamba.git
Allow creating environment with empty folder as target prefix (#3919)
This commit is contained in:
parent
5e0e879e0a
commit
cadd3c9e06
|
@ -44,8 +44,19 @@ namespace mamba
|
|||
{
|
||||
if (ctx.prefix_params.target_prefix == ctx.prefix_params.root_prefix)
|
||||
{
|
||||
LOG_ERROR << "Overwriting root prefix is not permitted";
|
||||
throw std::runtime_error("Aborting.");
|
||||
const auto message = "Overwriting root prefix is not permitted - aborting.";
|
||||
LOG_ERROR << message;
|
||||
throw mamba_error(message, mamba_error_code::incorrect_usage);
|
||||
}
|
||||
else if (!fs::is_directory(ctx.prefix_params.target_prefix))
|
||||
{
|
||||
const auto message = "Target prefix already exists and is not a folder - aborting.";
|
||||
LOG_ERROR << message;
|
||||
throw mamba_error(message, mamba_error_code::incorrect_usage);
|
||||
}
|
||||
else if (fs::is_empty(ctx.prefix_params.target_prefix))
|
||||
{
|
||||
LOG_WARNING << "Using existing empty folder as target prefix";
|
||||
}
|
||||
else if (fs::exists(ctx.prefix_params.target_prefix / "conda-meta"))
|
||||
{
|
||||
|
@ -64,8 +75,9 @@ namespace mamba
|
|||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR << "Non-conda folder exists at prefix";
|
||||
throw std::runtime_error("Aborting.");
|
||||
const auto message = "Non-conda folder exists at prefix - aborting.";
|
||||
LOG_ERROR << message;
|
||||
throw mamba_error(message, mamba_error_code::incorrect_usage);
|
||||
}
|
||||
}
|
||||
if (create_specs.empty())
|
||||
|
|
|
@ -246,6 +246,27 @@ def test_env_logging_overhead_regression(tmp_home, tmp_root_prefix, tmp_path):
|
|||
assert res["success"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("target_prefix", ("file", "empty_dir", "non_empty_dir"))
|
||||
def test_existing_target_prefix(tmp_root_prefix, tmp_path, target_prefix):
|
||||
p = tmp_path / "myenv"
|
||||
expected_p = p.resolve()
|
||||
cmd = ["-p", p]
|
||||
|
||||
if target_prefix == "file":
|
||||
expected_p.touch()
|
||||
else:
|
||||
expected_p.mkdir()
|
||||
if target_prefix == "non_empty_dir":
|
||||
(expected_p / "foo").touch()
|
||||
|
||||
if target_prefix in ("file", "non_empty_dir"):
|
||||
with pytest.raises(subprocess.CalledProcessError):
|
||||
helpers.create(*cmd)
|
||||
else:
|
||||
helpers.create(*cmd)
|
||||
assert (expected_p / "conda-meta").exists()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("shared_pkgs_dirs", [True], indirect=True)
|
||||
@pytest.mark.parametrize("root_prefix_type", (None, "env_var", "cli"))
|
||||
@pytest.mark.parametrize("target_is_root", (False, True))
|
||||
|
|
Loading…
Reference in New Issue