Verified Commit 875e1976 authored by Karel Koci's avatar Karel Koci 🤘

pkgupdate: add --reinstall-all option

This is intended to be used when we swich to different compilation tree
to force reinstall of all packages.
parent 0c8248ed
......@@ -38,7 +38,7 @@ local postprocess = require "postprocess"
module "planner"
-- luacheck: globals required_pkgs candidates_choose filter_required pkg_dep_iterate plan_sorter sat_penalize sat_pkg_group sat_dep sat_dep_traverse
-- luacheck: globals required_pkgs candidates_choose filter_required pkg_dep_iterate plan_sorter sat_penalize sat_pkg_group sat_dep sat_dep_traverse set_reinstall_all
-- Choose candidates that complies to version requirement.
function candidates_choose(candidates, pkg_name, version, repository)
......@@ -285,6 +285,15 @@ local function sat_build(sat, pkgs, requests)
end
local planned_action = 'require'
function set_reinstall_all(enable)
if enable then
planned_action = 'reinstall'
else
planned_action = 'require'
end
end
-- Iterate trough all packages in given dependency tree.
-- TODO This goes trough all dependencies, so even negative dependencies and
-- packages used only as conditionals are returned. This is harmless for what we
......@@ -418,7 +427,7 @@ local function build_plan(pkgs, requests, sat, satmap)
-- And finally plan it --
planned[name] = #plan + 1
r = {
action = 'require',
action = planned_action,
package = candidates[1],
modifier = (pkg or {}).modifier or {},
critical = false,
......@@ -594,8 +603,8 @@ local function check_install_version(status, requests)
-- Go through the requests and look which ones are needed and which ones are satisfied
for _, request in ipairs(requests) do
local installed_version = installed[request.name]
-- TODO: Handle stand-alone packages
local requested_version = utils.multi_index(request, "package", "Version") or ""
unused[request.name] = nil
if request.action == "require" then
if not installed_version or installed_version ~= requested_version then
DBG("Want to install " .. request.name)
......@@ -603,11 +612,9 @@ local function check_install_version(status, requests)
else
DBG("Package " .. request.name .. " already installed")
end
unused[request.name] = nil
elseif request.action == "reinstall" then
DBG("Want to reinstall " .. request.name)
install[request.name] = request
unused[request.name] = nil
else
DIE("Unknown action " .. request.action)
end
......
......@@ -9,6 +9,7 @@ static const char doc[] = "Updater-ng core tool. This updates system to latest v
enum option_val_prg {
OPT_BATCH_VAL = 300,
OPT_REINSTALL_ALL,
OPT_ASK_APPROVAL,
OPT_APPROVE,
OPT_TASKLOG,
......@@ -23,11 +24,12 @@ enum option_val_prg {
static struct argp_option options[] = {
{"batch", OPT_BATCH_VAL, NULL, 0, "Run without user confirmation.", 0},
{"ask-approval", OPT_ASK_APPROVAL, "FILE", 0, "Require user's approval to proceed (abort if --approve with appropriate ID is not present, plan of action is put into the FILE if approval is needed)", 0},
{"approve", OPT_APPROVE, "HASH", 0, "Approve actions with given HASH (multiple allowed).", 0},
{"out-of-root", OPT_OUT_OF_ROOT, NULL, 0, "We are running updater out of root filesystem. This implies --no-replan and --no-immediate-reboot and is suggested to be used with --root option.", 0},
{"task-log", OPT_TASK_LOG, "FILE", 0, "Append list of executed tasks into a log file.", 0},
{"state-log", OPT_STATE_LOG, NULL, 0, "Dump state to files in /tmp/updater-state directory", 0},
{"reinstall-all", OPT_REINSTALL_ALL, NULL, 0, "Reinstall packages that are already installed in latest version.", 0},
{"ask-approval", OPT_ASK_APPROVAL, "FILE", 0, "Require user's approval to proceed (abort if --approve with appropriate ID is not present, plan of action is put into the FILE if approval is needed)", 1},
{"approve", OPT_APPROVE, "HASH", 0, "Approve actions with given HASH (multiple allowed).", 1},
{"out-of-root", OPT_OUT_OF_ROOT, NULL, 0, "We are running updater out of root filesystem. This implies --no-replan and --no-immediate-reboot and is suggested to be used with --root option.", 2},
{"task-log", OPT_TASK_LOG, "FILE", 0, "Append list of executed tasks into a log file.", 2},
{"state-log", OPT_STATE_LOG, NULL, 0, "Dump state to files in /tmp/updater-state directory", 2},
// Following options are internal
{"reexec", OPT_REEXEC, NULL, OPTION_HIDDEN, "", 0},
{"reboot-finished", OPT_REBOOT_FINISHED, NULL, OPTION_HIDDEN, "", 0},
......@@ -40,6 +42,9 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
case OPT_BATCH_VAL:
opts->batch = true;
break;
case OPT_REINSTALL_ALL:
opts->reinstall_all = true;
break;
case OPT_ASK_APPROVAL:
opts->approval_file = arg;
break;
......
......@@ -24,6 +24,7 @@
struct opts {
bool batch; // --batch
bool reinstall_all; // --reinstall-all
const char *approval_file; // --ask-approval
const char **approve; // --approve
size_t approve_cnt;
......
......@@ -110,6 +110,7 @@ int main(int argc, char *argv[]) {
// Parse the arguments
struct opts opts = {
.batch = false,
.reinstall_all = false,
.approval_file = NULL,
.approve = NULL,
.approve_cnt = 0,
......@@ -137,6 +138,8 @@ int main(int argc, char *argv[]) {
err = interpreter_call(interpreter, "updater.disable_replan", NULL, "");
ASSERT_MSG(!err, "%s", err);
}
err = interpreter_call(interpreter, "planner.set_reinstall_all", NULL, "b", opts.reinstall_all);
ASSERT_MSG(!err, "%s", err);
// Check if we should recover previous execution first if so do
if (journal_exists(root_dir())) {
INFO("Detected existing journal. Trying to recover it.");
......
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