From 0d889c48f5664e73ef22b081a7ce1dae3c40812f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 24 Jun 2026 12:52:09 +0200 Subject: [PATCH] sysupdate: move cleanup verb up close to "vacuum" These are philosophically similar concepts: one deletes old versions based on whether they are old, and the other deletes old files based on whether they are orphaned, let's list them together. --- src/sysupdate/sysupdate.c | 114 +++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 57 deletions(-) diff --git a/src/sysupdate/sysupdate.c b/src/sysupdate/sysupdate.c index 54c2673569a..56f02811627 100644 --- a/src/sysupdate/sysupdate.c +++ b/src/sysupdate/sysupdate.c @@ -2282,6 +2282,63 @@ static int verb_vacuum(int argc, char *argv[], uintptr_t _data, void *userdata) return context_vacuum(&context, 0, NULL); } +VERB_NOARG(verb_cleanup, "cleanup", "Clean up orphaned files"); +static int verb_cleanup(int argc, char *argv[], uintptr_t _data, void *userdata) { + _cleanup_(context_done) Context context = CONTEXT_NULL; + int r; + + assert(argc <= 1); + + r = context_from_cmdline(&context); + if (r < 0) + return r; + + if (context.cleanup == 0) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invocation of 'cleanup' with --cleanup=no is contradictory, refusing."); + + r = context_load_offline( + &context, + /* process_image_flags= */ 0, + /* read_definitions_flags= */ 0); + if (r < 0) + return r; + + int ret = 0; + RET_GATHER(ret, installdb_cleanup_component(&context)); + + if (context.component_all) { + _cleanup_strv_free_ char **z = NULL; + r = installdb_list_components(&context, &z); + if (r < 0) + return log_error_errno(r, "Failed to enumerate components: %m"); + + STRV_FOREACH(i, z) { + _cleanup_(context_done) Context component_context = CONTEXT_NULL; + + r = context_from_cmdline(&component_context); + if (r < 0) + return r; + + /* Override the component with our iter. This needs to be done in a fresh Context + * as the installdb_fd and other state are specific to the component. */ + r = free_and_strdup_warn(&component_context.component, *i); + if (r < 0) + return r; + + r = context_load_offline( + &component_context, + /* process_image_flags= */ 0, + /* read_definitions_flags= */ 0); + if (r < 0) + return r; + + RET_GATHER(ret, installdb_cleanup_component(&component_context)); + } + } + + return ret; +} + VERB(verb_pending_or_reboot, "pending", NULL, 1, 1, 0, "Report whether a newer version is installed than currently booted"); VERB(verb_pending_or_reboot, "reboot", NULL, 1, 1, 0, @@ -2550,63 +2607,6 @@ static int verb_enable_component(int argc, char *argv[], uintptr_t _data, void * return 0; } -VERB_NOARG(verb_cleanup, "cleanup", "Clean up orphaned files"); -static int verb_cleanup(int argc, char *argv[], uintptr_t _data, void *userdata) { - _cleanup_(context_done) Context context = CONTEXT_NULL; - int r; - - assert(argc <= 1); - - r = context_from_cmdline(&context); - if (r < 0) - return r; - - if (context.cleanup == 0) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Invocation of 'cleanup' with --cleanup=no is contradictory, refusing."); - - r = context_load_offline( - &context, - /* process_image_flags= */ 0, - /* read_definitions_flags= */ 0); - if (r < 0) - return r; - - int ret = 0; - RET_GATHER(ret, installdb_cleanup_component(&context)); - - if (context.component_all) { - _cleanup_strv_free_ char **z = NULL; - r = installdb_list_components(&context, &z); - if (r < 0) - return log_error_errno(r, "Failed to enumerate components: %m"); - - STRV_FOREACH(i, z) { - _cleanup_(context_done) Context component_context = CONTEXT_NULL; - - r = context_from_cmdline(&component_context); - if (r < 0) - return r; - - /* Override the component with our iter. This needs to be done in a fresh Context - * as the installdb_fd and other state are specific to the component. */ - r = free_and_strdup_warn(&component_context.component, *i); - if (r < 0) - return r; - - r = context_load_offline( - &component_context, - /* process_image_flags= */ 0, - /* read_definitions_flags= */ 0); - if (r < 0) - return r; - - RET_GATHER(ret, installdb_cleanup_component(&component_context)); - } - } - - return ret; -} - static int help(void) { _cleanup_(table_unrefp) Table *common_options = NULL, *options = NULL, *verbs = NULL; int r; -- 2.47.3