]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/import/pull-job.c
import: allow file:// in addition to HTTP(S)
[thirdparty/systemd.git] / src / import / pull-job.c
index 8764207960b676e8cec4b2526950983a8078d368..826da953785d2b777c08ef15bd4a1a40d34aefdd 100644 (file)
@@ -117,7 +117,7 @@ static int pull_job_restart(PullJob *j, const char *new_url) {
 void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
         PullJob *j = NULL;
         CURLcode code;
-        long status;
+        long protocol;
         int r;
 
         if (curl_easy_getinfo(curl, CURLINFO_PRIVATE, (char **)&j) != CURLE_OK)
@@ -131,50 +131,62 @@ void pull_job_curl_on_finished(CurlGlue *g, CURL *curl, CURLcode result) {
                 goto finish;
         }
 
-        code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
+        code = curl_easy_getinfo(curl, CURLINFO_PROTOCOL, &protocol);
         if (code != CURLE_OK) {
                 r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
                 goto finish;
-        } else if (status == 304) {
-                log_info("Image already downloaded. Skipping download.");
-                j->etag_exists = true;
-                r = 0;
-                goto finish;
-        } else if (status >= 300) {
+        }
 
-                if (status == 404 && j->on_not_found) {
-                        _cleanup_free_ char *new_url = NULL;
+        if (IN_SET(protocol, CURLPROTO_HTTP, CURLPROTO_HTTPS)) {
+                long status;
 
-                        /* This resource wasn't found, but the implementor wants to maybe let us know a new URL, query for it. */
-                        r = j->on_not_found(j, &new_url);
-                        if (r < 0)
-                                goto finish;
+                code = curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &status);
+                if (code != CURLE_OK) {
+                        r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
+                        goto finish;
+                }
+
+                if (status == 304) {
+                        log_info("Image already downloaded. Skipping download.");
+                        j->etag_exists = true;
+                        r = 0;
+                        goto finish;
+                } else if (status >= 300) {
 
-                        if (r > 0) { /* A new url to use */
-                                assert(new_url);
+                        if (status == 404 && j->on_not_found) {
+                                _cleanup_free_ char *new_url = NULL;
 
-                                r = pull_job_restart(j, new_url);
+                                /* This resource wasn't found, but the implementor wants to maybe let us know a new URL, query for it. */
+                                r = j->on_not_found(j, &new_url);
                                 if (r < 0)
                                         goto finish;
 
-                                code = curl_easy_getinfo(j->curl, CURLINFO_RESPONSE_CODE, &status);
-                                if (code != CURLE_OK) {
-                                        r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
-                                        goto finish;
-                                }
+                                if (r > 0) { /* A new url to use */
+                                        assert(new_url);
+
+                                        r = pull_job_restart(j, new_url);
+                                        if (r < 0)
+                                                goto finish;
+
+                                        code = curl_easy_getinfo(j->curl, CURLINFO_RESPONSE_CODE, &status);
+                                        if (code != CURLE_OK) {
+                                                r = log_error_errno(SYNTHETIC_ERRNO(EIO), "Failed to retrieve response code: %s", curl_easy_strerror(code));
+                                                goto finish;
+                                        }
 
-                                if (status == 0)
-                                        return;
+                                        if (status == 0)
+                                                return;
+                                }
                         }
-                }
 
-                r = log_error_errno(
-                                status == 404 ? SYNTHETIC_ERRNO(ENOMEDIUM) : SYNTHETIC_ERRNO(EIO), /* Make the most common error recognizable */
-                                "HTTP request to %s failed with code %li.", j->url, status);
-                goto finish;
-        } else if (status < 200) {
-                r = log_error_errno(SYNTHETIC_ERRNO(EIO), "HTTP request to %s finished with unexpected code %li.", j->url, status);
-                goto finish;
+                        r = log_error_errno(
+                                        status == 404 ? SYNTHETIC_ERRNO(ENOMEDIUM) : SYNTHETIC_ERRNO(EIO), /* Make the most common error recognizable */
+                                        "HTTP request to %s failed with code %li.", j->url, status);
+                        goto finish;
+                } else if (status < 200) {
+                        r = log_error_errno(SYNTHETIC_ERRNO(EIO), "HTTP request to %s finished with unexpected code %li.", j->url, status);
+                        goto finish;
+                }
         }
 
         if (j->state != PULL_JOB_RUNNING) {