]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: Split context_apply() into acquire and install steps
authorPhilip Withnall <pwithnall@gnome.org>
Mon, 17 Nov 2025 15:14:19 +0000 (15:14 +0000)
committerPhilip Withnall <pwithnall@gnome.org>
Mon, 9 Feb 2026 11:54:25 +0000 (11:54 +0000)
This introduces no functional changes at the moment, but will be used in
upcoming commits.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Helps: https://github.com/systemd/systemd/issues/34814

src/sysupdate/sysupdate.c

index 05163754af71debe6fc52cb0449805bdb5fc73d3..e1143ad4ce407bf59cdc0de05f28795ee03c8311 100644 (file)
@@ -982,10 +982,9 @@ static int context_on_acquire_progress(const Transfer *t, const Instance *inst,
                                               overall, n - i, i, inst->metadata.version, overall);
 }
 
-static int context_apply(
+static int context_acquire(
                 Context *c,
-                const char *version,
-                UpdateSet **ret_applied) {
+                const char *version) {
 
         UpdateSet *us = NULL;
         int r;
@@ -1000,9 +999,6 @@ static int context_apply(
                 if (!c->candidate) {
                         log_info("No update needed.");
 
-                        if (ret_applied)
-                                *ret_applied = NULL;
-
                         return 0;
                 }
 
@@ -1014,9 +1010,6 @@ static int context_apply(
         else if (FLAGS_SET(us->flags, UPDATE_INSTALLED)) {
                 log_info("Selected update '%s' is already installed. Skipping update.", us->version);
 
-                if (ret_applied)
-                        *ret_applied = NULL;
-
                 return 0;
         }
 
@@ -1075,7 +1068,34 @@ static int context_apply(
         if (arg_sync)
                 sync();
 
-        (void) sd_notifyf(/* unset_environment= */ false,
+        return 1;
+}
+
+static int context_install(
+                Context *c,
+                const char *version,
+                UpdateSet **ret_applied) {
+
+        UpdateSet *us = NULL;
+        int r;
+
+        assert(c);
+
+        if (version) {
+                us = context_update_set_by_version(c, version);
+                if (!us)
+                        return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Update '%s' not found.", version);
+        } else {
+                if (!c->candidate) {
+                        log_info("No update needed.");
+
+                        return 0;
+                }
+
+                us = c->candidate;
+        }
+
+        (void) sd_notifyf(/* unset_environment=*/ false,
                           "STATUS=Installing '%s'.", us->version);
 
         for (size_t i = 0; i < c->n_transfers; i++) {
@@ -1443,7 +1463,12 @@ static int verb_update(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return r;
 
-        r = context_apply(context, version, &applied);
+        r = context_acquire(context, version);
+        if (r < 0)
+                return r;  /* error */
+
+        if (r > 0)  /* update needed */
+                r = context_install(context, version, &applied);
         if (r < 0)
                 return r;