]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sysupdate: fix features and vaccum if all features are disabled
authorThorsten Kukuk <kukuk@suse.com>
Fri, 28 Feb 2025 13:01:16 +0000 (14:01 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 5 Mar 2025 15:53:27 +0000 (00:53 +0900)
If all transfer definitions are features and disabled, a wrong error
is reported that there are no transfer definitions.
This breaks the features and vaccum verb, as they work on disabled
features, too.

src/sysupdate/sysupdate.c

index 2bdd71e74272e64ae8c17b25b09317d064769762..9ced67429ac2b61475ffb64e3315eadfc78ca939 100644 (file)
@@ -172,7 +172,7 @@ static int read_definitions(
         return 0;
 }
 
-static int context_read_definitions(Context *c, const char* node) {
+static int context_read_definitions(Context *c, const char* node, bool requires_enabled_transfers) {
         _cleanup_strv_free_ char **dirs = NULL, **files = NULL;
         int r;
 
@@ -241,7 +241,7 @@ static int context_read_definitions(Context *c, const char* node) {
                         log_warning("As of v257, transfer definitions should have the '.transfer' extension.");
         }
 
-        if (c->n_transfers == 0) {
+        if (c->n_transfers + (requires_enabled_transfers ? 0 : c->n_disabled_transfers) == 0) {
                 if (arg_component)
                         return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
                                                "No transfer definitions for component '%s' found.",
@@ -899,7 +899,7 @@ static int context_vacuum(
         return 0;
 }
 
-static int context_make_offline(Context **ret, const char *node) {
+static int context_make_offline(Context **ret, const char *node, bool requires_enabled_transfers) {
         _cleanup_(context_freep) Context* context = NULL;
         int r;
 
@@ -912,7 +912,7 @@ static int context_make_offline(Context **ret, const char *node) {
         if (!context)
                 return log_oom();
 
-        r = context_read_definitions(context, node);
+        r = context_read_definitions(context, node, requires_enabled_transfers);
         if (r < 0)
                 return r;
 
@@ -933,7 +933,7 @@ static int context_make_online(Context **ret, const char *node) {
         /* Like context_make_offline(), but also communicates with the update source looking for new
          * versions (as long as --offline is not specified on the command line). */
 
-        r = context_make_offline(&context, node);
+        r = context_make_offline(&context, node, /* requires_enabled_transfers= */ true);
         if (r < 0)
                 return r;
 
@@ -1217,7 +1217,7 @@ static int verb_features(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return r;
 
-        r = context_make_offline(&context, loop_device ? loop_device->node : NULL);
+        r = context_make_offline(&context, loop_device ? loop_device->node : NULL, /* requires_enabled_transfers= */ false);
         if (r < 0)
                 return r;
 
@@ -1392,7 +1392,7 @@ static int verb_vacuum(int argc, char **argv, void *userdata) {
         if (r < 0)
                 return r;
 
-        r = context_make_offline(&context, loop_device ? loop_device->node : NULL);
+        r = context_make_offline(&context, loop_device ? loop_device->node : NULL, /* requires_enabled_transfers= */ false);
         if (r < 0)
                 return r;
 
@@ -1469,7 +1469,7 @@ static int verb_pending_or_reboot(int argc, char **argv, void *userdata) {
                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                        "The --root=/--image= switches may not be combined with the '%s' operation.", argv[0]);
 
-        r = context_make_offline(&context, NULL);
+        r = context_make_offline(&context, /* node= */ NULL, /* requires_enabled_transfers= */ true);
         if (r < 0)
                 return r;