diff options
-rw-r--r-- | src/import/import-dkr.c | 34 | ||||
-rw-r--r-- | src/import/import-dkr.h | 4 | ||||
-rw-r--r-- | src/import/import.c | 4 |
3 files changed, 23 insertions, 19 deletions
diff --git a/src/import/import-dkr.c b/src/import/import-dkr.c index 205deb9cda..594da547f5 100644 --- a/src/import/import-dkr.c +++ b/src/import/import-dkr.c @@ -76,7 +76,6 @@ struct DkrImportJob { struct DkrImportName { DkrImport *import; - char *index_url; char *name; char *tag; char *id; @@ -94,6 +93,8 @@ struct DkrImport { sd_event *event; CurlGlue *glue; + char *index_url; + Hashmap *names; Hashmap *jobs; @@ -163,7 +164,6 @@ static DkrImportName *dkr_import_name_unref(DkrImportName *name) { if (name->job_layer) set_remove(name->job_layer->needed_by, name); - free(name->index_url); free(name->name); free(name->id); free(name->tag); @@ -998,16 +998,18 @@ static int dkr_import_name_begin(DkrImportName *name) { assert(name); assert(!name->job_images); - url = strappenda(name->index_url, "/v1/repositories/", name->name, "/images"); + url = strappenda(name->import->index_url, "/v1/repositories/", name->name, "/images"); return dkr_import_name_add_job(name, DKR_IMPORT_JOB_IMAGES, url, &name->job_images); } -int dkr_import_new(DkrImport **import, sd_event *event, dkr_import_on_finished on_finished, void *userdata) { +int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, dkr_import_on_finished on_finished, void *userdata) { _cleanup_(dkr_import_unrefp) DkrImport *i = NULL; + char *e; int r; assert(import); + assert(dkr_url_is_valid(index_url)); i = new0(DkrImport, 1); if (!i) @@ -1016,6 +1018,14 @@ int dkr_import_new(DkrImport **import, sd_event *event, dkr_import_on_finished o i->on_finished = on_finished; i->userdata = userdata; + i->index_url = strdup(index_url); + if (!i->index_url) + return -ENOMEM; + + e = endswith(i->index_url, "/"); + if (e) + *e = 0; + if (event) i->event = sd_event_ref(event); else { @@ -1055,6 +1065,8 @@ DkrImport* dkr_import_unref(DkrImport *import) { curl_glue_unref(import->glue); sd_event_unref(import->event); + free(import->index_url); + free(import); return NULL; @@ -1074,13 +1086,11 @@ int dkr_import_cancel(DkrImport *import, const char *name) { return 1; } -int dkr_import_pull(DkrImport *import, const char *index_url, const char *name, const char *tag, const char *local, bool force_local) { +int dkr_import_pull(DkrImport *import, const char *name, const char *tag, const char *local, bool force_local) { _cleanup_(dkr_import_name_unrefp) DkrImportName *n = NULL; - char *e; int r; assert(import); - assert(dkr_url_is_valid(index_url)); assert(dkr_name_is_valid(name)); assert(dkr_tag_is_valid(tag)); assert(!local || machine_name_is_valid(local)); @@ -1098,13 +1108,6 @@ int dkr_import_pull(DkrImport *import, const char *index_url, const char *name, n->import = import; - n->index_url = strdup(index_url); - if (!n->index_url) - return -ENOMEM; - e = endswith(n->index_url, "/"); - if (e) - *e = 0; - n->name = strdup(name); if (!n->name) return -ENOMEM; @@ -1132,7 +1135,6 @@ int dkr_import_pull(DkrImport *import, const char *index_url, const char *name, } n = NULL; - return 0; } @@ -1168,6 +1170,8 @@ bool dkr_id_is_valid(const char *id) { } bool dkr_url_is_valid(const char *url) { + if (isempty(url)) + return false; if (!startswith(url, "http://") && !startswith(url, "https://")) diff --git a/src/import/import-dkr.h b/src/import/import-dkr.h index a95169590b..8e6a462cc7 100644 --- a/src/import/import-dkr.h +++ b/src/import/import-dkr.h @@ -26,12 +26,12 @@ typedef struct DkrImport DkrImport; typedef void (*dkr_import_on_finished)(DkrImport *import, int error, void *userdata); -int dkr_import_new(DkrImport **import, sd_event *event, dkr_import_on_finished on_finished, void *userdata); +int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, dkr_import_on_finished on_finished, void *userdata); DkrImport* dkr_import_unref(DkrImport *import); DEFINE_TRIVIAL_CLEANUP_FUNC(DkrImport*, dkr_import_unref); -int dkr_import_pull(DkrImport *import, const char *index_url, const char *name, const char *tag, const char *local, bool force_local); +int dkr_import_pull(DkrImport *import, const char *name, const char *tag, const char *local, bool force_local); int dkr_import_cancel(DkrImport *import, const char *name); bool dkr_name_is_valid(const char *name); diff --git a/src/import/import.c b/src/import/import.c index 11d2e05f09..8b9ca4f724 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -115,11 +115,11 @@ static int pull_dkr(int argc, char *argv[], void *userdata) { sd_event_add_signal(event, NULL, SIGTERM, NULL, NULL); sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); - r = dkr_import_new(&import, event, on_finished, event); + r = dkr_import_new(&import, event, arg_dkr_index_url, on_dkr_finished, event); if (r < 0) return log_error_errno(r, "Failed to allocate importer: %m"); - r = dkr_import_pull(import, arg_dkr_index_url, name, tag, local, arg_force); + r = dkr_import_pull(import, name, tag, local, arg_force); if (r < 0) return log_error_errno(r, "Failed to pull image: %m"); |