aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-01-27 12:05:15 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-01-27 12:30:41 +0300
commit8da486bf54453c092ac99fd1c352b0f0d98dcc6f (patch)
tree8a5fdc972c4ca799bc59df0a83302c4941831eb0
parent147747d23ee97352be23ead6323a5ff5d51ac49c (diff)
Allow multiple <distribution>-name values
-rw-r--r--bpkg/system-package-manager.cxx43
-rw-r--r--bpkg/system-package-manager.hxx15
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<repository_fragment> 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 <name> component matches the
// specified distribution name and the <version> 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<reference_wrapper<const distribution_name_value>>;
-
auto name_values = [&aps] (const string& n, const semantic_version& v)
{
- values r;
+ strings r;
for (const auto& a: aps)
{
const shared_ptr<available_package>& 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 <distribution>-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 <distribution>-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<repository_fragment>& af (a.second);
shared_ptr<repository_fragment> 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&,