]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: move cleanup verb up close to "vacuum" 42947/head
authorLennart Poettering <lennart@amutable.com>
Wed, 24 Jun 2026 10:52:09 +0000 (12:52 +0200)
committerLennart Poettering <lennart@amutable.com>
Fri, 10 Jul 2026 12:37:17 +0000 (14:37 +0200)
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

index 54c2673569a952a125a627c87f6688b97303071f..56f02811627befd3993a5eb58a608fea8630a6f3 100644 (file)
@@ -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;