aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2023-01-30 16:45:00 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2023-01-30 16:45:00 +0300
commit2903ad8d65a76e9ae6da9a8c4ac13591aeb879d8 (patch)
tree210f2c2fb56967f914c824646b004506418c4d4e
parent41083007e6b1d2e434663c2d6c074e806e417ea9 (diff)
Fix resulting names ordering for system_package_names()
-rw-r--r--bpkg/system-package-manager.cxx44
-rw-r--r--bpkg/system-package-manager.test.testscript3
2 files changed, 36 insertions, 11 deletions
diff --git a/bpkg/system-package-manager.cxx b/bpkg/system-package-manager.cxx
index 3585ba3..b5fa333 100644
--- a/bpkg/system-package-manager.cxx
+++ b/bpkg/system-package-manager.cxx
@@ -197,27 +197,53 @@ namespace bpkg
auto name_values = [&aps] (const string& n, const semantic_version& v)
{
strings r;
+
+ // For each available package sort the system package names in the
+ // distribution version descending order and then append them to the
+ // resulting list, keeping this order and suppressing duplicates.
+ //
+ using name_version = pair<string, semantic_version>;
+ vector<name_version> nvs; // Reuse the buffer.
+
for (const auto& a: aps)
{
+ nvs.clear ();
+
const shared_ptr<available_package>& ap (a.first);
- for (const distribution_name_value& nv: ap->distribution_values)
+ for (const distribution_name_value& dv: ap->distribution_values)
{
- if (optional<string> d = nv.distribution ("-name"))
+ if (optional<string> d = dv.distribution ("-name"))
{
pair<string, semantic_version> dnv (
- parse_distribution (move (*d), nv.name, ap, a.second));
+ parse_distribution (move (*d), dv.name, ap, a.second));
- if (dnv.first == n &&
- dnv.second <= v &&
- find_if (r.begin (), r.end (),
- [&nv] (const string& v) {return nv.value == v;}) ==
- r.end ())
+ if (dnv.first == n && dnv.second <= v)
{
- r.push_back (nv.value);
+ // Add the name/version pair to the sorted vector.
+ //
+ name_version nv (make_pair (dv.value, move (dnv.second)));
+
+ nvs.insert (upper_bound (nvs.begin (), nvs.end (), nv,
+ [] (const name_version& x,
+ const name_version& y)
+ {return x.second > y.second;}),
+ move (nv));
}
}
}
+
+ // Append the sorted names to the resulting list.
+ //
+ for (name_version& nv: nvs)
+ {
+ if (find_if (r.begin (), r.end (),
+ [&nv] (const string& n) {return nv.first == n;}) ==
+ r.end ())
+ {
+ r.push_back (move (nv.first));
+ }
+ }
}
return r;
diff --git a/bpkg/system-package-manager.test.testscript b/bpkg/system-package-manager.test.testscript
index b993793..dc672f5 100644
--- a/bpkg/system-package-manager.test.testscript
+++ b/bpkg/system-package-manager.test.testscript
@@ -26,14 +26,13 @@
summary: curl
license: curl
EOI
-#\
+
$* debian 10 -- libcurl libcurl7.64.manifest libcurl7.84.manifest >>EOO;
libcurl4 libcurl4-openssl-dev
libcurl3-gnutls libcurl4-gnutls-dev
libcurl2 libcurl2-dev libcurl2-doc
libcurl2 libcurl2-dev
EOO
-#\
$* debian 9 -- libcurl libcurl7.64.manifest libcurl7.84.manifest >>EOO;
libcurl2 libcurl2-dev libcurl2-doc
libcurl2 libcurl2-dev