Commit 054cbeb4 authored by Karel Koci's avatar Karel Koci 🤘

Sort candidates in package group

Candidates in package groups are now sorted as part of postprocess.
This sorting is required for correct precedence of candidates during
dependency computations.
parent 05a61639
......@@ -337,6 +337,7 @@ function pkg_aggregate()
end
modifier.replan = modifier.replan or m.replan
end
-- Canonize dependencies
modifier.deps = deps_canon(modifier.deps)
for _, candidate in ipairs(pkg_group.candidates or {}) do
candidate.deps = deps_canon(candidate.deps) or {} -- deps from updater configuration file
......@@ -347,6 +348,23 @@ function pkg_aggregate()
pkg_group.modifier = modifier
-- We merged them together, they are no longer needed separately
pkg_group.modifiers = nil
-- Sort candidates
if pkg_group.candidates then
table.sort(pkg_group.candidates, function(a, b)
if a.repo.priority ~= b.repo.priority then -- Check repository priority
return a.repo.priority > b.repo.priority
end
local vers_cmp = backend.version_cmp(a.Version, b.Version)
if vers_cmp ~= 0 then -- Check version of package
return vers_cmp == 1 -- a is newer version than b
end
if a.repo.serial ~= b.repo.serial then -- Check repo order of introduction
return a.repo.serial < b.repo.serial
end
WARN("Multiple candidates from same repository with same version for package " .. a.Package)
return true -- lets prioritize a, for no reason, lets make b angry.
end)
end
end
end
......
......@@ -187,8 +187,8 @@ function test_pkg_merge()
[""] = {
tp = 'pkg-list',
list = {
xyz = {Package = "xyz"},
abc = {Package = "abc"}
xyz = {Package = "xyz", Version = "1"},
abc = {Package = "abc", Version = "2"}
}
}
}
......@@ -198,19 +198,29 @@ function test_pkg_merge()
a = {
tp = 'pkg-list',
list = {
abc = {Package = "abc"}
abc = {Package = "abc", Version = "1"}
}
},
b = {
tp = 'pkg-list',
list = {
another = {Package = "another"}
another = {Package = "another", Version = "4"}
}
},
c = utils.exception("Just an exception", "Just an exception")
}
}
}
-- Add repo field
for _, repo in pairs(requests.known_repositories_all) do
for _, cont in pairs(repo.content) do
if cont.tp == 'pkg-list' then
for _, pkg in pairs(cont.list) do
pkg.repo = repo
end
end
end
end
requests.known_packages = {
{
tp = 'package',
......@@ -236,11 +246,14 @@ function test_pkg_merge()
-- Build the expected data structure
local exp = {
abc = {
candidates = {{Package = "abc", deps = {}}, {Package = "abc", deps = {}}},
candidates = {
{Package = "abc", Version = "2", deps = {}, repo = requests.known_repositories_all[1]},
{Package = "abc", Version = "1", deps = {}, repo = requests.known_repositories_all[2]}
},
modifier = {name = "abc"}
},
another = {
candidates = {{Package = "another", deps = {}}},
candidates = {{Package = "another", Version = "4", deps = {}, repo = requests.known_repositories_all[2]}},
modifier = {name = "another"}
},
virt = {
......@@ -249,7 +262,7 @@ function test_pkg_merge()
virtual = true
},
xyz = {
candidates = {{Package = "xyz", deps = {}}},
candidates = {{Package = "xyz", Version = "1", deps = {}, repo = requests.known_repositories_all[1]}},
modifier = {
name = "xyz",
order_after = {abc = true},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment