Commit 3a03f539 authored by Karel Koci's avatar Karel Koci 🤘

Order remove requests in plan by dependencies

Requests with some dependency on other to be removed packages is now in
plan before such packages.
parent a2f0af67
......@@ -33,6 +33,7 @@ local picosat = picosat
local utils = require "utils"
local backend = require "backend"
local requests = require "requests"
local postprocess = require "postprocess"
module "planner"
......@@ -523,15 +524,33 @@ function filter_required(status, requests)
end
end
-- Go through the packages that are installed and nobody mentioned them and mark them for removal
-- TODO: Order them according to dependencies
-- TODO report cycles in dependencies
local unused_sorted = {}
local sort_buff = {}
local function sort_unused(pkg)
if not sort_buff[pkg] then
sort_buff[pkg] = true
-- Unfortunately we have to go trough all dependencies to ensure correct order.
local deps = postprocess.deps_canon(utils.multi_index(status, pkg, "Depends") or {})
for _, deppkg in pkg_dep_iterate(deps) do
sort_unused(deppkg.name or deppkg)
end
if unused[pkg] then
unused[pkg] = nil
DBG("Want to remove left-over package " .. pkg)
table.insert(unused_sorted, {
action = "remove",
name = pkg,
package = status[pkg]
})
end
-- Ignore packages that are used or not installed at all
end
end
for pkg in pairs(unused) do
DBG("Want to remove left-over package " .. pkg)
table.insert(result, {
action = "remove",
name = pkg,
package = status[pkg]
})
sort_unused(pkg)
end
utils.arr_append(result, utils.arr_inv(unused_sorted))
-- If we are requested to replan after some package, wipe the rest of the plan
local wipe = false
for i, request in ipairs(result) do
......
......@@ -716,7 +716,11 @@ function test_filter_required()
Version = "3"
},
pkg4 = {
Depends = "pkg5 nonexist",
Version = "4"
},
pkg5 = {
Version = "5"
}
}
local requests = {
......@@ -750,13 +754,13 @@ function test_filter_required()
},
modifier = {}
},
-- The pkg4 is not mentioned, it shall be uninstalled at the end
-- The pkg4 and pkg5 are not mentioned, they shall be uninstalled at the end
{
-- Not installed and we want it
action = "require",
name = "pkg5",
name = "pkg6",
package = {
Version = "5",
Version = "6",
repo = def_repo
},
modifier = {}
......@@ -779,9 +783,18 @@ function test_filter_required()
action = "remove",
name = "pkg4",
package = {
Depends = "pkg5 nonexist",
Version = "4"
-- No repo field here, this comes from the status, there are no repositories
}
},
{
action = "remove",
name = "pkg5",
package = {
Version = "5"
-- No repo field here, this comes from the status, there are no repositories
}
}
}
assert_table_equal(expected, result)
......
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