From 8da486bf54453c092ac99fd1c352b0f0d98dcc6f Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Fri, 27 Jan 2023 12:05:15 +0300 Subject: Allow multiple -name values --- bpkg/system-package-manager.cxx | 43 ++++++++++++++--------------------------- bpkg/system-package-manager.hxx | 15 +++++++++----- 2 files changed, 25 insertions(+), 33 deletions(-) diff --git a/bpkg/system-package-manager.cxx b/bpkg/system-package-manager.cxx index e31f0ac..bf4b968 100644 --- a/bpkg/system-package-manager.cxx +++ b/bpkg/system-package-manager.cxx @@ -159,7 +159,9 @@ namespace bpkg // used in tests. // shared_ptr f (af.get_eager ()); - database* db (f == nullptr || af.loaded () ? &af.database () : nullptr); + database* db (!(f != nullptr && !af.loaded ()) // Not transient? + ? &af.database () + : nullptr); diag_record dr (fail); dr << "invalid distribution version '" << string (dn, p + 1) @@ -190,14 +192,11 @@ namespace bpkg // specified available packages whose component matches the // specified distribution name and the component (assumed as "0" // if not present) is less or equal the specified distribution version. - // Suppress duplicate entries with the same name (so that distribution - // values of the later available package versions are preferred) or value. + // Suppress duplicate values. // - using values = vector>; - auto name_values = [&aps] (const string& n, const semantic_version& v) { - values r; + strings r; for (const auto& a: aps) { const shared_ptr& ap (a.first); @@ -212,11 +211,10 @@ namespace bpkg if (dnv.first == n && dnv.second <= v && find_if (r.begin (), r.end (), - [&nv] (const distribution_name_value& v) - {return v.name == nv.name || v.value == nv.value;}) == + [&nv] (const string& v) {return nv.value == v;}) == r.end ()) { - r.push_back (nv); + r.push_back (nv.value); } } } @@ -225,36 +223,25 @@ namespace bpkg return r; }; - // Collect the -name values that match the name id and refer - // to the version which is less or equal than the version id. + // Collect distribution values for those -name names which + // match the name id and refer to the version which is less or equal than + // the version id. // - values vs (name_values (name_id, vid)); + strings r (name_values (name_id, vid)); // If the resulting list is empty and the like ids are specified, then // re-collect but now using the like id and "0" version id instead. // - if (vs.empty ()) + if (r.empty ()) { for (const string& like_id: like_ids) { - vs = name_values (like_id, semantic_version (0, 0, 0)); - if (!vs.empty ()) + r = name_values (like_id, semantic_version (0, 0, 0)); + if (!r.empty ()) break; } } - // Return the values of the collected name/values list. - // - strings r; - if (size_t n = vs.size ()) - { - r.reserve (n); - - transform (vs.begin (), vs.end (), - back_inserter (r), - [] (const distribution_name_value& v) {return v.value;}); - } - return r; } @@ -314,7 +301,7 @@ namespace bpkg // const lazy_shared_ptr& af (a.second); shared_ptr f (af.get_eager ()); - database* db (f == nullptr || af.loaded () + database* db (!(f != nullptr && !af.loaded ()) // Not transient? ? &af.database () : nullptr); diff --git a/bpkg/system-package-manager.hxx b/bpkg/system-package-manager.hxx index 35b7439..a47608a 100644 --- a/bpkg/system-package-manager.hxx +++ b/bpkg/system-package-manager.hxx @@ -196,11 +196,16 @@ namespace bpkg // something more elaborate, like translate version_id to the like_id's // version and try that). // - // @@ TODO: allow multiple -name values per same distribution and handle - // here? E.g., libcurl4-openssl-dev libcurl4-gnutls-dev. But they will - // have the same available version, how will we deal with that? How - // will we pick one? Perhaps this should all be handled by the system - // package manager (conceptually, this is configuration negotiation). + // Note that multiple -name values per same distribution can be returned + // as, for example, for the following distribution values: + // + // debian_10-name: libcurl4 libcurl4-doc libcurl4-openssl-dev + // debian_10-name: libcurl3-gnutls libcurl4-gnutls-dev (yes, 3 and 4) + // + // @@ TODO: But they will have the same available version, how will we + // deal with that? How will we pick one? Perhaps this should all be + // handled by the system package manager (conceptually, this is + // configuration negotiation). // static strings system_package_names (const available_packages&, -- cgit v1.1