diff --git a/src/import/pull-job.c b/src/import/pull-job.c index 80197d6c57..dcdb1fe8fa 100644 --- a/src/import/pull-job.c +++ b/src/import/pull-job.c @@ -99,15 +99,19 @@ static void pull_job_finish(PullJob *j, int ret) { j->on_finished(j); } -static int pull_job_restart(PullJob *j, const char *new_url) { +int pull_job_restart(PullJob *j, const char *new_url) { int r; assert(j); - assert(new_url); - r = free_and_strdup(&j->url, new_url); - if (r < 0) - return r; + /* If an URL is specified we retry the same request, just towards a different URL. If the URL is NULL + * then we'll fire the same request again (which is useful if some parameters have been changed) */ + + if (new_url) { + r = free_and_strdup(&j->url, new_url); + if (r < 0) + return r; + } j->state = PULL_JOB_INIT; j->error = 0; @@ -119,16 +123,17 @@ static int pull_job_restart(PullJob *j, const char *new_url) { j->etag_exists = false; j->mtime = 0; iovec_done(&j->checksum); - iovec_done(&j->expected_checksum); - j->expected_content_length = UINT64_MAX; j->content_type = mfree(j->content_type); + if (new_url) { + /* Reset expectations if the URL changes */ + iovec_done(&j->expected_checksum); + j->expected_content_length = UINT64_MAX; + } + curl_glue_remove_and_free(j->glue, j->curl); j->curl = NULL; - curl_slist_free_all(j->request_header); - j->request_header = NULL; - import_compress_free(&j->compress); if (j->checksum_ctx) { diff --git a/src/import/pull-job.h b/src/import/pull-job.h index bfbdb8cced..ea58b62f3b 100644 --- a/src/import/pull-job.h +++ b/src/import/pull-job.h @@ -104,4 +104,6 @@ int pull_job_add_request_header(PullJob *j, const char *hdr); int pull_job_set_accept(PullJob *j, char * const *l); int pull_job_set_bearer_token(PullJob *j, const char *token); +int pull_job_restart(PullJob *j, const char *new_url); + DEFINE_TRIVIAL_CLEANUP_FUNC(PullJob*, pull_job_unref);