summaryrefslogtreecommitdiff
path: root/src/import/pull.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/import/pull.c')
-rw-r--r--src/import/pull.c81
1 files changed, 45 insertions, 36 deletions
diff --git a/src/import/pull.c b/src/import/pull.c
index ee3ff68036..eec4583868 100644
--- a/src/import/pull.c
+++ b/src/import/pull.c
@@ -25,11 +25,12 @@
#include "event-util.h"
#include "verbs.h"
#include "build.h"
+#include "signal-util.h"
#include "machine-image.h"
-#include "import-tar.h"
-#include "import-raw.h"
-#include "import-dkr.h"
#include "import-util.h"
+#include "pull-tar.h"
+#include "pull-raw.h"
+#include "pull-dkr.h"
static bool arg_force = false;
static const char *arg_image_root = "/var/lib/machines";
@@ -42,9 +43,9 @@ static int interrupt_signal_handler(sd_event_source *s, const struct signalfd_si
return 0;
}
-static void on_tar_finished(TarImport *import, int error, void *userdata) {
+static void on_tar_finished(TarPull *pull, int error, void *userdata) {
sd_event *event = userdata;
- assert(import);
+ assert(pull);
if (error == 0)
log_info("Operation completed successfully.");
@@ -53,7 +54,7 @@ static void on_tar_finished(TarImport *import, int error, void *userdata) {
}
static int pull_tar(int argc, char *argv[], void *userdata) {
- _cleanup_(tar_import_unrefp) TarImport *import = NULL;
+ _cleanup_(tar_pull_unrefp) TarPull *pull = NULL;
_cleanup_event_unref_ sd_event *event = NULL;
const char *url, *local;
_cleanup_free_ char *l = NULL, *ll = NULL;
@@ -112,11 +113,11 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
- r = tar_import_new(&import, event, arg_image_root, on_tar_finished, event);
+ r = tar_pull_new(&pull, event, arg_image_root, on_tar_finished, event);
if (r < 0)
- return log_error_errno(r, "Failed to allocate importer: %m");
+ return log_error_errno(r, "Failed to allocate puller: %m");
- r = tar_import_pull(import, url, local, arg_force, arg_verify);
+ r = tar_pull_start(pull, url, local, arg_force, arg_verify);
if (r < 0)
return log_error_errno(r, "Failed to pull image: %m");
@@ -128,9 +129,9 @@ static int pull_tar(int argc, char *argv[], void *userdata) {
return -r;
}
-static void on_raw_finished(RawImport *import, int error, void *userdata) {
+static void on_raw_finished(RawPull *pull, int error, void *userdata) {
sd_event *event = userdata;
- assert(import);
+ assert(pull);
if (error == 0)
log_info("Operation completed successfully.");
@@ -139,7 +140,7 @@ static void on_raw_finished(RawImport *import, int error, void *userdata) {
}
static int pull_raw(int argc, char *argv[], void *userdata) {
- _cleanup_(raw_import_unrefp) RawImport *import = NULL;
+ _cleanup_(raw_pull_unrefp) RawPull *pull = NULL;
_cleanup_event_unref_ sd_event *event = NULL;
const char *url, *local;
_cleanup_free_ char *l = NULL, *ll = NULL;
@@ -198,11 +199,11 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
- r = raw_import_new(&import, event, arg_image_root, on_raw_finished, event);
+ r = raw_pull_new(&pull, event, arg_image_root, on_raw_finished, event);
if (r < 0)
- return log_error_errno(r, "Failed to allocate importer: %m");
+ return log_error_errno(r, "Failed to allocate puller: %m");
- r = raw_import_pull(import, url, local, arg_force, arg_verify);
+ r = raw_pull_start(pull, url, local, arg_force, arg_verify);
if (r < 0)
return log_error_errno(r, "Failed to pull image: %m");
@@ -214,9 +215,9 @@ static int pull_raw(int argc, char *argv[], void *userdata) {
return -r;
}
-static void on_dkr_finished(DkrImport *import, int error, void *userdata) {
+static void on_dkr_finished(DkrPull *pull, int error, void *userdata) {
sd_event *event = userdata;
- assert(import);
+ assert(pull);
if (error == 0)
log_info("Operation completed successfully.");
@@ -225,9 +226,9 @@ static void on_dkr_finished(DkrImport *import, int error, void *userdata) {
}
static int pull_dkr(int argc, char *argv[], void *userdata) {
- _cleanup_(dkr_import_unrefp) DkrImport *import = NULL;
+ _cleanup_(dkr_pull_unrefp) DkrPull *pull = NULL;
_cleanup_event_unref_ sd_event *event = NULL;
- const char *name, *tag, *local;
+ const char *name, *reference, *local, *digest;
int r;
if (!arg_dkr_index_url) {
@@ -236,17 +237,23 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
}
if (arg_verify != IMPORT_VERIFY_NO) {
- log_error("Imports from dkr do not support image verification, please pass --verify=no.");
+ log_error("Pulls from dkr do not support image verification, please pass --verify=no.");
return -EINVAL;
}
- tag = strchr(argv[1], ':');
- if (tag) {
- name = strndupa(argv[1], tag - argv[1]);
- tag++;
+ digest = strchr(argv[1], '@');
+ if (digest) {
+ reference = digest + 1;
+ name = strndupa(argv[1], digest - argv[1]);
+ }
+
+ reference = strchr(argv[1], ':');
+ if (reference) {
+ name = strndupa(argv[1], reference - argv[1]);
+ reference++;
} else {
name = argv[1];
- tag = "latest";
+ reference = "latest";
}
if (!dkr_name_is_valid(name)) {
@@ -254,8 +261,8 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
return -EINVAL;
}
- if (!dkr_tag_is_valid(tag)) {
- log_error("Tag name '%s' is not valid.", tag);
+ if (!dkr_ref_is_valid(reference)) {
+ log_error("Tag name '%s' is not valid.", reference);
return -EINVAL;
}
@@ -288,9 +295,9 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
}
}
- log_info("Pulling '%s' with tag '%s', saving as '%s'.", name, tag, local);
+ log_info("Pulling '%s' with reference '%s', saving as '%s'.", name, reference, local);
} else
- log_info("Pulling '%s' with tag '%s'.", name, tag);
+ log_info("Pulling '%s' with reference '%s'.", name, reference);
r = sd_event_default(&event);
if (r < 0)
@@ -300,11 +307,11 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
sd_event_add_signal(event, NULL, SIGTERM, interrupt_signal_handler, NULL);
sd_event_add_signal(event, NULL, SIGINT, interrupt_signal_handler, NULL);
- r = dkr_import_new(&import, event, arg_dkr_index_url, arg_image_root, on_dkr_finished, event);
+ r = dkr_pull_new(&pull, event, arg_dkr_index_url, arg_image_root, on_dkr_finished, event);
if (r < 0)
- return log_error_errno(r, "Failed to allocate importer: %m");
+ return log_error_errno(r, "Failed to allocate puller: %m");
- r = dkr_import_pull(import, name, tag, local, arg_force);
+ r = dkr_pull_start(pull, name, reference, local, arg_force, DKR_PULL_V2);
if (r < 0)
return log_error_errno(r, "Failed to pull image: %m");
@@ -319,13 +326,13 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
static int help(int argc, char *argv[], void *userdata) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
- "Import container or virtual machine image.\n\n"
+ "Download container or virtual machine images.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --force Force creation of image\n"
" --verify= Verify downloaded image, one of: 'no',\n"
" 'checksum', 'signature'.\n"
- " --image-root= Image root directory\n"
+ " --image-root=PATH Image root directory\n"
" --dkr-index-url=URL Specify index URL to use for downloads\n\n"
"Commands:\n"
" tar URL [NAME] Download a TAR image\n"
@@ -409,7 +416,7 @@ static int parse_argv(int argc, char *argv[]) {
return 1;
}
-static int import_main(int argc, char *argv[]) {
+static int pull_main(int argc, char *argv[]) {
static const Verb verbs[] = {
{ "help", VERB_ANY, VERB_ANY, 0, help },
@@ -433,7 +440,9 @@ int main(int argc, char *argv[]) {
if (r <= 0)
goto finish;
- r = import_main(argc, argv);
+ ignore_signals(SIGPIPE, -1);
+
+ r = pull_main(argc, argv);
finish:
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;