static void tar_import_job_on_progress(ImportJob *j) { TarImport *i; assert(j); assert(j->userdata); i = j->userdata; tar_import_report_progress(i, TAR_DOWNLOADING); }
static int tar_import_process(TarImport *i) { ssize_t l; int r; assert(i); assert(i->buffer_size < sizeof(i->buffer)); l = read(i->input_fd, i->buffer + i->buffer_size, sizeof(i->buffer) - i->buffer_size); if (l < 0) { if (errno == EAGAIN) return 0; r = log_error_errno(errno, "Failed to read input file: %m"); goto finish; } if (l == 0) { if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) { log_error("Premature end of file: %m"); r = -EIO; goto finish; } r = tar_import_finish(i); goto finish; } i->buffer_size += l; if (i->compress.type == IMPORT_COMPRESS_UNKNOWN) { r = import_uncompress_detect(&i->compress, i->buffer, i->buffer_size); if (r < 0) { log_error("Failed to detect file compression: %m"); goto finish; } if (r == 0) /* Need more data */ return 0; r = tar_import_fork_tar(i); if (r < 0) goto finish; } r = import_uncompress(&i->compress, i->buffer, i->buffer_size, tar_import_write, i); if (r < 0) { log_error_errno(r, "Failed to decode and write: %m"); goto finish; } i->written_compressed += i->buffer_size; i->buffer_size = 0; tar_import_report_progress(i); return 0; finish: if (i->on_finished) i->on_finished(i, r, i->userdata); else sd_event_exit(i->event, r); return 0; }
static void tar_import_job_on_finished(ImportJob *j) { TarImport *i; int r; assert(j); assert(j->userdata); i = j->userdata; if (j->error != 0) { if (j == i->checksum_job) log_error_errno(j->error, "Failed to retrieve SHA256 checksum, cannot verify. (Try --verify=no?)"); else if (j == i->signature_job) log_error_errno(j->error, "Failed to retrieve signature file, cannot verify. (Try --verify=no?)"); else log_error_errno(j->error, "Failed to retrieve image file. (Wrong URL?)"); r = j->error; goto finish; } /* This is invoked if either the download completed * successfully, or the download was skipped because we * already have the etag. */ if (!tar_import_is_done(i)) return; j->disk_fd = safe_close(i->tar_job->disk_fd); if (i->tar_pid > 0) { r = wait_for_terminate_and_warn("tar", i->tar_pid, true); i->tar_pid = 0; if (r < 0) goto finish; } if (!i->tar_job->etag_exists) { /* This is a new download, verify it, and move it into place */ tar_import_report_progress(i, TAR_VERIFYING); r = import_verify(i->tar_job, i->checksum_job, i->signature_job); if (r < 0) goto finish; tar_import_report_progress(i, TAR_FINALIZING); r = import_make_read_only(i->temp_path); if (r < 0) goto finish; if (rename(i->temp_path, i->final_path) < 0) { r = log_error_errno(errno, "Failed to rename to final image name: %m"); goto finish; } free(i->temp_path); i->temp_path = NULL; } tar_import_report_progress(i, TAR_COPYING); r = tar_import_make_local_copy(i); if (r < 0) goto finish; r = 0; finish: if (i->on_finished) i->on_finished(i, r, i->userdata); else sd_event_exit(i->event, r); }