j->etag_exists = false;
j->mtime = 0;
j->checksum = mfree(j->checksum);
+ j->expected_content_length = UINT64_MAX;
curl_glue_remove_and_free(j->glue, j->curl);
j->curl = NULL;
return 0;
}
+static uint64_t pull_job_content_length_effective(PullJob *j) {
+ assert(j);
+
+ if (j->expected_content_length != UINT64_MAX)
+ return j->expected_content_length;
+
+ return j->content_length;
+}
+
void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
PullJob *j = NULL;
char *scheme = NULL;
goto finish;
}
- if (j->content_length != UINT64_MAX &&
- j->content_length != j->written_compressed) {
+ uint64_t cl = pull_job_content_length_effective(j);
+ if (cl != UINT64_MAX &&
+ cl != j->written_compressed) {
r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Download truncated.");
goto finish;
}
if (j->written_compressed + sz > j->compressed_max)
return log_error_errno(SYNTHETIC_ERRNO(EFBIG), "File overly large, refusing.");
- if (j->content_length != UINT64_MAX &&
- j->written_compressed + sz > j->content_length)
+ uint64_t cl = pull_job_content_length_effective(j);
+ if (cl != UINT64_MAX &&
+ j->written_compressed + sz > cl)
return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
"Content length incorrect.");
goto fail;
}
+ if (j->expected_content_length != UINT64_MAX &&
+ j->expected_content_length != j->content_length) {
+ r = log_error_errno(SYNTHETIC_ERRNO(EPROTO), "Content does not have expected size.");
+ goto fail;
+ }
+
log_info("Downloading %s for %s.", FORMAT_BYTES(j->content_length), j->url);
}
.url = TAKE_PTR(u),
.offset = UINT64_MAX,
.sync = true,
+ .expected_content_length = UINT64_MAX,
};
*ret = TAKE_PTR(j);