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;
if (!c->candidate) {
log_info("No update needed.");
- if (ret_applied)
- *ret_applied = NULL;
-
return 0;
}
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;
}
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++) {
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;