- log_warning_errno(errno, "Failed to set file attributes on %s: %m", f->temp_path);
-
- r = copy_bytes(f->disk_fd, dfd, (off_t) -1, true);
- if (r < 0) {
- log_error_errno(r, "Failed to make writable copy of image: %m");
- unlink(tp);
- goto finish;
- }
-
- (void) copy_times(f->disk_fd, dfd);
- (void) copy_xattr(f->disk_fd, dfd);
-
- dfd = safe_close(dfd);
-
- r = rename(tp, p);
- if (r < 0) {
- r = log_error_errno(errno, "Failed to move writable image into place: %m");
- unlink(tp);
- goto finish;
- }
-
- log_info("Created new local image %s.", p);
- }
-
- f->disk_fd = safe_close(f->disk_fd);
- r = 0;
-
-finish:
- raw_import_finish(f->import, r);
-}
-
-static void raw_import_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
- RawImportFile *f = NULL;
- struct stat st;
- CURLcode code;
- long status;
- int r;
-
- if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, &f) != CURLE_OK)
- return;
-
- if (!f || f->done)
- return;
-
- f->done = true;
-
- if (result != CURLE_OK) {
- log_error("Transfer failed: %s", curl_easy_strerror(result));
- r = -EIO;
- goto fail;
- }
-
- code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
- if (code != CURLE_OK) {
- log_error("Failed to retrieve response code: %s", curl_easy_strerror(code));
- r = -EIO;
- goto fail;
- } else if (status == 304) {
- log_info("Image already downloaded. Skipping download.");
- raw_import_file_success(f);
- return;
- } else if (status >= 300) {
- log_error("HTTP request to %s failed with code %li.", f->url, status);
- r = -EIO;
- goto fail;
- } else if (status < 200) {
- log_error("HTTP request to %s finished with unexpected code %li.", f->url, status);
- r = -EIO;
- goto fail;
- }
-
- if (f->disk_fd < 0) {
- log_error("No data received.");
- r = -EIO;
- goto fail;
- }
-
- if (f->content_length != (uint64_t) -1 &&
- f->content_length != f->written_compressed) {
- log_error("Download truncated.");
- r = -EIO;
- goto fail;
- }
-
- if (f->etag)
- (void) fsetxattr(f->disk_fd, "user.source_etag", f->etag, strlen(f->etag), 0);
- if (f->url)
- (void) fsetxattr(f->disk_fd, "user.source_url", f->url, strlen(f->url), 0);
-
- if (f->mtime != 0) {
- struct timespec ut[2];
-
- timespec_store(&ut[0], f->mtime);
- ut[1] = ut[0];
- (void) futimens(f->disk_fd, ut);
-
- fd_setcrtime(f->disk_fd, f->mtime);
- }
-
- if (fstat(f->disk_fd, &st) < 0) {
- r = log_error_errno(errno, "Failed to stat file: %m");
- goto fail;
- }
-
- /* Mark read-only */
- (void) fchmod(f->disk_fd, st.st_mode & 07444);
-
- assert(f->temp_path);
- assert(f->final_path);
-
- r = rename(f->temp_path, f->final_path);
- if (r < 0) {
- r = log_error_errno(errno, "Failed to move RAW file into place: %m");
- goto fail;