Skip to content

Commit

Permalink
Fix MatchSpec dist parse
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoinePrv committed Dec 26, 2023
1 parent d79b328 commit 1e346ba
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
7 changes: 4 additions & 3 deletions libmamba/src/core/env_lockfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,14 @@ namespace mamba
std::type_index{ typeid(err) }
));
}
catch (...)
catch (const std::exception& e)
{
return tl::unexpected(EnvLockFileError::make_error(
file_parsing_error_code::parsing_failure,
fmt::format(
"unknown error while reading environment lockfile located at '{}'",
file_path.string()
"Error while reading environment lockfile located at '{}': {}",
file_path.string(),
e.what()
)
));
}
Expand Down
23 changes: 9 additions & 14 deletions libmamba/src/core/match_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,29 +66,24 @@ namespace mamba
out.m_filename = std::string(pkg);
out.m_url = util::path_or_url_to_url(spec);

// Name
auto [head, tail] = util::split_once(specs::strip_archive_extension(pkg), '-');
out.m_name = head;
if (!tail.has_value())
// Build string
auto [head, tail] = util::rsplit_once(specs::strip_archive_extension(pkg), '-');
out.build_string = tail;
if (!head.has_value())
{
fail_parse();
}

// Version
std::tie(head, tail) = util::split_once(tail.value(), '-');
out.version = head;
if (!tail.has_value())
std::tie(head, tail) = util::rsplit_once(head.value(), '-');
out.version = tail;
if (!head.has_value())
{
fail_parse();
}

// Build string
std::tie(head, tail) = util::split_once(tail.value(), '-');
out.build_string = head;
if (tail.has_value()) // Exactly three expected
{
fail_parse();
}
// Name
out.m_name = head.value(); // There may be '-' in the name

return out;
}
Expand Down
13 changes: 13 additions & 0 deletions libmamba/tests/src/core/test_match_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,19 @@ TEST_SUITE("MatchSpec")
);
CHECK_EQ(ms.filename(), "_libgcc_mutex-0.1-conda_forge.tar.bz2");
}
{
auto ms = MatchSpec::parse(
"https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-11.2.0-h1d223b6_13.tar.bz2"
);
CHECK_EQ(ms.name(), "libgcc-ng");
CHECK_EQ(ms.version, "11.2.0");
CHECK_EQ(ms.build_string, "h1d223b6_13");
CHECK_EQ(
ms.url(),
"https://conda.anaconda.org/conda-forge/linux-64/libgcc-ng-11.2.0-h1d223b6_13.tar.bz2"
);
CHECK_EQ(ms.filename(), "libgcc-ng-11.2.0-h1d223b6_13.tar.bz2");
}
{
auto ms = MatchSpec::parse(
"/home/randomguy/Downloads/linux-64/_libgcc_mutex-0.1-conda_forge.tar.bz2"
Expand Down

0 comments on commit 1e346ba

Please sign in to comment.