Skip to content

Commit

Permalink
Rework how curl errors are checked
Browse files Browse the repository at this point in the history
In cases where curl perform returns an error but is actually a 400
level response, swupd needs to check curl info to see this. If the
info reveals a 400 level response, return the corresponding download
status error to prevent useless download retries.

Signed-off-by: William Douglas <[email protected]>
  • Loading branch information
bryteise committed Apr 4, 2024
1 parent bee9d51 commit e083168
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/swupd_lib/curl.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,23 @@ enum download_status process_curl_error_codes(int curl_ret, CURL *curl_handle)
return DOWNLOAD_STATUS_ERROR;
}
} else { /* download failed but let our caller do it */
long response = 0;
curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &response);
debug("Curl - process_curl_error_codes: curl_ret = %d, response = %ld\n", curl_ret, response);
switch (response) {
case 403:
debug("Curl - Download failed - forbidden (403) - '%s'\n", url);
return DOWNLOAD_STATUS_FORBIDDEN;
case 404:
debug("Curl - Download failed - file not found (404) - '%s'\n", url);
return DOWNLOAD_STATUS_NOT_FOUND;
case 416:
debug("Curl - Download failed - range not satisfiable (416) - '%s'\n", url);
return DOWNLOAD_STATUS_RANGE_NOT_SATISFIABLE;
default:
error("Curl - Download failed: response (%ld) - '%s'\n", response, url);
}

debug("Curl - process_curl_error_codes - curl_ret = %d\n", curl_ret);
switch (curl_ret) {
case CURLE_COULDNT_RESOLVE_PROXY:
Expand Down

0 comments on commit e083168

Please sign in to comment.