Commit 8095f629 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,26 @@ 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
local vers_cmp = backend.version_cmp(a.Version, b.Version)
if vers_cmp == 0 then -- Check version of package
if a.repo.serial == b.repo.serial then -- Check repo order of introduction
WARN("Multiple candidates from same repository with same version for package " .. a.Package)
return false -- lets prioritize a, for no reason, lets make b angry.
else
return a.repo.serial < b.repo.serial
end
else
return vers_cmp == 1 -- b is newer version than a
end
else
return a.repo.priority > b.repo.priority
end
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,23 @@ 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")
}
}
}
requests.known_repositories_all[1].content[""].list.xyz.repo = requests.known_repositories_all[1]
requests.known_repositories_all[1].content[""].list.abc.repo = requests.known_repositories_all[1]
requests.known_repositories_all[2].content.a.list.abc.repo = requests.known_repositories_all[2]
requests.known_repositories_all[2].content.b.list.another.repo = requests.known_repositories_all[2]
requests.known_packages = {
{
tp = 'package',
......@@ -236,11 +240,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 +256,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