From 1e346ba4da7975bda0fdcc0dda45f29edb459908 Mon Sep 17 00:00:00 2001 From: AntoinePrv Date: Tue, 26 Dec 2023 11:45:33 +0100 Subject: [PATCH] Fix MatchSpec dist parse --- libmamba/src/core/env_lockfile.cpp | 7 ++++--- libmamba/src/core/match_spec.cpp | 23 ++++++++------------- libmamba/tests/src/core/test_match_spec.cpp | 13 ++++++++++++ 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/libmamba/src/core/env_lockfile.cpp b/libmamba/src/core/env_lockfile.cpp index c674cf4119..a4868053b2 100644 --- a/libmamba/src/core/env_lockfile.cpp +++ b/libmamba/src/core/env_lockfile.cpp @@ -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() ) )); } diff --git a/libmamba/src/core/match_spec.cpp b/libmamba/src/core/match_spec.cpp index 3379b789d7..8835064b90 100644 --- a/libmamba/src/core/match_spec.cpp +++ b/libmamba/src/core/match_spec.cpp @@ -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; } diff --git a/libmamba/tests/src/core/test_match_spec.cpp b/libmamba/tests/src/core/test_match_spec.cpp index 70b1a1d23c..c6ef649598 100644 --- a/libmamba/tests/src/core/test_match_spec.cpp +++ b/libmamba/tests/src/core/test_match_spec.cpp @@ -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"