]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
importd: optionally allow clients to specify alternative image root
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Feb 2025 10:52:21 +0000 (11:52 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 21 Feb 2025 09:03:32 +0000 (10:03 +0100)
src/import/importd.c
src/shared/varlink-io.systemd.Import.c

index 8e1fe51bf8d5344775d3d29083b4adcc368a58a5..324bb618a450723ec17b63a3e167e265cae7fadb 100644 (file)
@@ -73,6 +73,7 @@ struct Transfer {
 
         char *remote;
         char *local;
+        char *image_root;
         ImageClass class;
         ImportFlags flags;
         char *format;
@@ -146,6 +147,7 @@ static Transfer *transfer_unref(Transfer *t) {
         free(t->remote);
         free(t->local);
         free(t->format);
+        free(t->image_root);
         free(t->object_path);
 
         pidref_done_sigkill_wait(&t->pidref);
@@ -455,6 +457,8 @@ static int transfer_start(Transfer *t) {
                         NULL, /* if so: the actual URL */
                         NULL, /* maybe --format= */
                         NULL, /* if so: the actual format */
+                        NULL, /* maybe --image-root= */
+                        NULL, /* if so: the image root path */
                         NULL, /* remote */
                         NULL, /* local */
                         NULL
@@ -548,6 +552,11 @@ static int transfer_start(Transfer *t) {
                         cmd[k++] = t->format;
                 }
 
+                if (t->image_root) {
+                        cmd[k++] = "--image-root";
+                        cmd[k++] = t->image_root;
+                }
+
                 if (!IN_SET(t->type, TRANSFER_EXPORT_TAR, TRANSFER_EXPORT_RAW)) {
                         if (t->remote)
                                 cmd[k++] = t->remote;
@@ -1838,6 +1847,7 @@ static int vl_method_pull(sd_varlink *link, sd_json_variant *parameters, sd_varl
                 bool force;
                 bool read_only;
                 bool keep_download;
+                const char *image_root;
         } p = {
                 .class = _IMAGE_CLASS_INVALID,
                 .verify = IMPORT_VERIFY_SIGNATURE,
@@ -1852,6 +1862,7 @@ static int vl_method_pull(sd_varlink *link, sd_json_variant *parameters, sd_varl
                 { "force",        SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool,      offsetof(struct p, force),         0                 },
                 { "readOnly",     SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool,      offsetof(struct p, read_only),     0                 },
                 { "keepDownload", SD_JSON_VARIANT_BOOLEAN, sd_json_dispatch_stdbool,      offsetof(struct p, keep_download), 0                 },
+                { "imageRoot",    SD_JSON_VARIANT_BOOLEAN, json_dispatch_const_path,      offsetof(struct p, image_root),    SD_JSON_STRICT    },
                 VARLINK_DISPATCH_POLKIT_FIELD,
                 {},
         };
@@ -1918,6 +1929,12 @@ static int vl_method_pull(sd_varlink *link, sd_json_variant *parameters, sd_varl
                         return -ENOMEM;
         }
 
+        if (p.image_root) {
+                t->image_root = strdup(p.image_root);
+                if (!t->image_root)
+                        return -ENOMEM;
+        }
+
         r = transfer_start(t);
         if (r < 0)
                 return r;
index 66030e63fc004b0d1bb1f69ad8cdb0375ae907d3..400a4429d6ce7d74c13f44322412e9ba393c4357 100644 (file)
@@ -91,6 +91,8 @@ static SD_VARLINK_DEFINE_METHOD_FULL(
                 SD_VARLINK_DEFINE_INPUT(readOnly, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
                 SD_VARLINK_FIELD_COMMENT("Whether to keep a pristine copy of the download separate from the locally installed image. Defaults to false."),
                 SD_VARLINK_DEFINE_INPUT(keepDownload, SD_VARLINK_BOOL, SD_VARLINK_NULLABLE),
+                SD_VARLINK_FIELD_COMMENT("Root directory for images. If not specified derived from the image class, and located below /var/lib/."),
+                SD_VARLINK_DEFINE_INPUT(imageRoot, SD_VARLINK_STRING, SD_VARLINK_NULLABLE),
                 VARLINK_DEFINE_POLKIT_INPUT,
                 SD_VARLINK_FIELD_COMMENT("A progress update, as percent value"),
                 SD_VARLINK_DEFINE_OUTPUT(progress, SD_VARLINK_FLOAT, SD_VARLINK_NULLABLE),