]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
pull-job: make sure pull_job_restart() can be used to fetch the same resource again...
authorLennart Poettering <lennart@amutable.com>
Fri, 7 Nov 2025 07:32:39 +0000 (08:32 +0100)
committerLennart Poettering <lennart@amutable.com>
Thu, 19 Feb 2026 14:05:15 +0000 (15:05 +0100)
Let's flush out all response state from the job, but let's keep the
request data previously configured, in particular the headers set. This
is useful to re-request a resource, just with a slightly modified or
identical URL.

src/import/pull-job.c
src/import/pull-job.h

index 80197d6c57e625a229d25bafd5e83f5242017974..dcdb1fe8fa7b31e830911733fa71b1f13ac0bc6b 100644 (file)
@@ -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) {
index bfbdb8cced694076013cd0dc5b53b124a882f31a..ea58b62f3bfa94ce311ed83f6798c55517e576d4 100644 (file)
@@ -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);