From: Lennart Poettering Date: Mon, 10 Feb 2025 10:52:21 +0000 (+0100) Subject: importd: optionally allow clients to specify alternative image root X-Git-Tag: v258-rc1~1280^2~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=576c97e16576facb0a37239272b65f6d4f198081;p=thirdparty%2Fsystemd.git importd: optionally allow clients to specify alternative image root --- diff --git a/src/import/importd.c b/src/import/importd.c index 8e1fe51bf8d..324bb618a45 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -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; diff --git a/src/shared/varlink-io.systemd.Import.c b/src/shared/varlink-io.systemd.Import.c index 66030e63fc0..400a4429d6c 100644 --- a/src/shared/varlink-io.systemd.Import.c +++ b/src/shared/varlink-io.systemd.Import.c @@ -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),