int tar_pull_start(TarPull *i, const char *url, const char *local, bool force_local, ImportVerify verify) { int r; assert(i); if (!http_url_is_valid(url)) return -EINVAL; if (local && !machine_name_is_valid(local)) return -EINVAL; if (i->tar_job) return -EBUSY; r = free_and_strdup(&i->local, local); if (r < 0) return r; i->force_local = force_local; i->verify = verify; r = pull_job_new(&i->tar_job, url, i->glue, i); if (r < 0) return r; i->tar_job->on_finished = tar_pull_job_on_finished; i->tar_job->on_open_disk = tar_pull_job_on_open_disk; i->tar_job->on_progress = tar_pull_job_on_progress; i->tar_job->calc_checksum = verify != IMPORT_VERIFY_NO; i->tar_job->grow_machine_directory = i->grow_machine_directory; r = pull_find_old_etags(url, i->image_root, DT_DIR, ".tar-", NULL, &i->tar_job->old_etags); if (r < 0) return r; r = pull_make_verification_jobs(&i->checksum_job, &i->signature_job, verify, url, i->glue, tar_pull_job_on_finished, i); if (r < 0) return r; r = pull_job_begin(i->tar_job); if (r < 0) return r; if (i->checksum_job) { i->checksum_job->on_progress = tar_pull_job_on_progress; r = pull_job_begin(i->checksum_job); if (r < 0) return r; } if (i->signature_job) { i->signature_job->on_progress = tar_pull_job_on_progress; r = pull_job_begin(i->signature_job); if (r < 0) return r; } return 0; }
static int dkr_pull_pull_layer(DkrPull *i) { _cleanup_free_ char *path = NULL; const char *url, *layer = NULL; int r; assert(i); assert(!i->layer_job); assert(!i->temp_path); assert(!i->final_path); for (;;) { layer = dkr_pull_current_layer(i); if (!layer) return 0; /* no more layers */ path = strjoin(i->image_root, "/.dkr-", layer, NULL); if (!path) return log_oom(); if (laccess(path, F_OK) < 0) { if (errno == ENOENT) break; return log_error_errno(errno, "Failed to check for container: %m"); } log_info("Layer %s already exists, skipping.", layer); i->current_ancestry++; free(path); path = NULL; } log_info("Pulling layer %s...", layer); i->final_path = path; path = NULL; url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/images/", layer, "/layer"); r = pull_job_new(&i->layer_job, url, i->glue, i); if (r < 0) return log_error_errno(r, "Failed to allocate layer job: %m"); r = dkr_pull_add_token(i, i->layer_job); if (r < 0) return log_oom(); i->layer_job->on_finished = dkr_pull_job_on_finished; i->layer_job->on_open_disk = dkr_pull_job_on_open_disk; i->layer_job->on_progress = dkr_pull_job_on_progress; i->layer_job->grow_machine_directory = i->grow_machine_directory; r = pull_job_begin(i->layer_job); if (r < 0) return log_error_errno(r, "Failed to start layer job: %m"); return 0; }
int raw_pull_start( RawPull *i, const char *url, const char *local, bool force_local, ImportVerify verify, bool settings, bool roothash) { int r; assert(i); assert(verify < _IMPORT_VERIFY_MAX); assert(verify >= 0); if (!http_url_is_valid(url)) return -EINVAL; if (local && !machine_name_is_valid(local)) return -EINVAL; if (i->raw_job) return -EBUSY; r = free_and_strdup(&i->local, local); if (r < 0) return r; i->force_local = force_local; i->verify = verify; i->settings = settings; i->roothash = roothash; /* Queue job for the image itself */ r = pull_job_new(&i->raw_job, url, i->glue, i); if (r < 0) return r; i->raw_job->on_finished = raw_pull_job_on_finished; i->raw_job->on_open_disk = raw_pull_job_on_open_disk_raw; i->raw_job->on_progress = raw_pull_job_on_progress; i->raw_job->calc_checksum = verify != IMPORT_VERIFY_NO; i->raw_job->grow_machine_directory = i->grow_machine_directory; r = pull_find_old_etags(url, i->image_root, DT_REG, ".raw-", ".raw", &i->raw_job->old_etags); if (r < 0) return r; if (roothash) { r = pull_make_auxiliary_job(&i->roothash_job, url, raw_strip_suffixes, ".roothash", i->glue, raw_pull_job_on_finished, i); if (r < 0) return r; i->roothash_job->on_open_disk = raw_pull_job_on_open_disk_roothash; i->roothash_job->on_progress = raw_pull_job_on_progress; i->roothash_job->calc_checksum = verify != IMPORT_VERIFY_NO; } if (settings) { r = pull_make_auxiliary_job(&i->settings_job, url, raw_strip_suffixes, ".nspawn", i->glue, raw_pull_job_on_finished, i); if (r < 0) return r; i->settings_job->on_open_disk = raw_pull_job_on_open_disk_settings; i->settings_job->on_progress = raw_pull_job_on_progress; i->settings_job->calc_checksum = verify != IMPORT_VERIFY_NO; } r = pull_make_verification_jobs(&i->checksum_job, &i->signature_job, verify, url, i->glue, raw_pull_job_on_finished, i); if (r < 0) return r; r = pull_job_begin(i->raw_job); if (r < 0) return r; if (i->roothash_job) { r = pull_job_begin(i->roothash_job); if (r < 0) return r; } if (i->settings_job) { r = pull_job_begin(i->settings_job); if (r < 0) return r; } if (i->checksum_job) { i->checksum_job->on_progress = raw_pull_job_on_progress; i->checksum_job->style = VERIFICATION_PER_FILE; r = pull_job_begin(i->checksum_job); if (r < 0) return r; } if (i->signature_job) { i->signature_job->on_progress = raw_pull_job_on_progress; r = pull_job_begin(i->signature_job); if (r < 0) return r; } return 0; }
int tar_pull_start( TarPull *i, const char *url, const char *local, bool force_local, ImportVerify verify, bool settings) { int r; assert(i); assert(verify < _IMPORT_VERIFY_MAX); assert(verify >= 0); if (!http_url_is_valid(url)) return -EINVAL; if (local && !machine_name_is_valid(local)) return -EINVAL; if (i->tar_job) return -EBUSY; r = free_and_strdup(&i->local, local); if (r < 0) return r; i->force_local = force_local; i->verify = verify; i->settings = settings; /* Set up download job for TAR file */ r = pull_job_new(&i->tar_job, url, i->glue, i); if (r < 0) return r; i->tar_job->on_finished = tar_pull_job_on_finished; i->tar_job->on_open_disk = tar_pull_job_on_open_disk_tar; i->tar_job->on_progress = tar_pull_job_on_progress; i->tar_job->calc_checksum = verify != IMPORT_VERIFY_NO; i->tar_job->grow_machine_directory = i->grow_machine_directory; r = pull_find_old_etags(url, i->image_root, DT_DIR, ".tar-", NULL, &i->tar_job->old_etags); if (r < 0) return r; /* Set up download job for the settings file (.nspawn) */ if (settings) { r = pull_make_auxiliary_job(&i->settings_job, url, tar_strip_suffixes, ".nspawn", i->glue, tar_pull_job_on_finished, i); if (r < 0) return r; i->settings_job->on_open_disk = tar_pull_job_on_open_disk_settings; i->settings_job->on_progress = tar_pull_job_on_progress; i->settings_job->calc_checksum = verify != IMPORT_VERIFY_NO; } /* Set up download of checksum/signature files */ r = pull_make_verification_jobs(&i->checksum_job, &i->signature_job, verify, url, i->glue, tar_pull_job_on_finished, i); if (r < 0) return r; r = pull_job_begin(i->tar_job); if (r < 0) return r; if (i->settings_job) { r = pull_job_begin(i->settings_job); if (r < 0) return r; } if (i->checksum_job) { i->checksum_job->on_progress = tar_pull_job_on_progress; i->checksum_job->style = VERIFICATION_PER_FILE; r = pull_job_begin(i->checksum_job); if (r < 0) return r; } if (i->signature_job) { i->signature_job->on_progress = tar_pull_job_on_progress; r = pull_job_begin(i->signature_job); if (r < 0) return r; } return 0; }