mirror of
https://github.com/systemd/systemd.git
synced 2025-01-13 17:18:18 +03:00
import: simplify dkr importer, by making use of generic import-job logic, used by the raw and tar importers
This gets us progress output as well xz/bzip2 support.
This commit is contained in:
parent
8b71fce8c2
commit
ff2670ad11
File diff suppressed because it is too large
Load Diff
@ -24,17 +24,15 @@
|
||||
|
||||
typedef struct DkrImport DkrImport;
|
||||
|
||||
typedef void (*dkr_import_on_finished)(DkrImport *import, int error, void *userdata);
|
||||
typedef void (*DkrImportFinished)(DkrImport *import, int error, void *userdata);
|
||||
|
||||
int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, const char *image_root, dkr_import_on_finished on_finished, void *userdata);
|
||||
int dkr_import_new(DkrImport **import, sd_event *event, const char *index_url, const char *image_root, DkrImportFinished 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 *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);
|
||||
bool dkr_id_is_valid(const char *id);
|
||||
#define dkr_tag_is_valid(tag) filename_is_valid(tag)
|
||||
bool dkr_url_is_valid(const char *url);
|
||||
|
@ -573,6 +573,12 @@ static size_t import_job_header_callback(void *contents, size_t size, size_t nme
|
||||
return sz;
|
||||
}
|
||||
|
||||
if (j->on_header) {
|
||||
r = j->on_header(j, contents, sz);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return sz;
|
||||
|
||||
fail:
|
||||
@ -672,10 +678,22 @@ int import_job_begin(ImportJob *j) {
|
||||
if (!hdr)
|
||||
return -ENOMEM;
|
||||
|
||||
j->request_header = curl_slist_new(hdr, NULL);
|
||||
if (!j->request_header)
|
||||
return -ENOMEM;
|
||||
if (!j->request_header) {
|
||||
j->request_header = curl_slist_new(hdr, NULL);
|
||||
if (!j->request_header)
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
struct curl_slist *l;
|
||||
|
||||
l = curl_slist_append(j->request_header, hdr);
|
||||
if (!l)
|
||||
return -ENOMEM;
|
||||
|
||||
j->request_header = l;
|
||||
}
|
||||
}
|
||||
|
||||
if (j->request_header) {
|
||||
if (curl_easy_setopt(j->curl, CURLOPT_HTTPHEADER, j->request_header) != CURLE_OK)
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ typedef struct ImportJob ImportJob;
|
||||
|
||||
typedef void (*ImportJobFinished)(ImportJob *job);
|
||||
typedef int (*ImportJobOpenDisk)(ImportJob *job);
|
||||
typedef int (*ImportJobHeader)(ImportJob*job, const char *header, size_t sz);
|
||||
|
||||
typedef enum ImportJobState {
|
||||
IMPORT_JOB_INIT,
|
||||
@ -64,6 +65,7 @@ struct ImportJob {
|
||||
void *userdata;
|
||||
ImportJobFinished on_finished;
|
||||
ImportJobOpenDisk on_open_disk;
|
||||
ImportJobHeader on_header;
|
||||
|
||||
CurlGlue *glue;
|
||||
CURL *curl;
|
||||
|
@ -283,10 +283,8 @@ static void on_dkr_finished(DkrImport *import, int error, void *userdata) {
|
||||
|
||||
if (error == 0)
|
||||
log_info("Operation completed successfully.");
|
||||
else
|
||||
log_error_errno(error, "Operation failed: %m");
|
||||
|
||||
sd_event_exit(event, error);
|
||||
sd_event_exit(event, EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int pull_dkr(int argc, char *argv[], void *userdata) {
|
||||
@ -338,21 +336,20 @@ static int pull_dkr(int argc, char *argv[], void *userdata) {
|
||||
local = NULL;
|
||||
|
||||
if (local) {
|
||||
const char *p;
|
||||
|
||||
if (!machine_name_is_valid(local)) {
|
||||
log_error("Local image name '%s' is not valid.", local);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
p = strappenda(arg_image_root, "/", local);
|
||||
if (laccess(p, F_OK) >= 0) {
|
||||
if (!arg_force) {
|
||||
log_info("Image '%s' already exists.", local);
|
||||
return 0;
|
||||
if (!arg_force) {
|
||||
r = image_find(local, NULL);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to check whether image '%s' exists: %m", local);
|
||||
else if (r > 0) {
|
||||
log_error_errno(EEXIST, "Image '%s' already exists.", local);
|
||||
return -EEXIST;
|
||||
}
|
||||
} else if (errno != ENOENT)
|
||||
return log_error_errno(errno, "Can't check if image '%s' already exists: %m", local);
|
||||
}
|
||||
|
||||
log_info("Pulling '%s' with tag '%s', saving as '%s'.", name, tag, local);
|
||||
} else
|
||||
@ -445,7 +442,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
break;
|
||||
|
||||
case ARG_DKR_INDEX_URL:
|
||||
if (!dkr_url_is_valid(optarg)) {
|
||||
if (!http_url_is_valid(optarg)) {
|
||||
log_error("Index URL is not valid: %s", optarg);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user