dload: avoid using CURLOPT_FAILONERROR

Use of this flag causes connections to be closed on 404s -- a common
occurrence when your config sets DatabaseOptional. Handle the error
gracefully, so that the connection can be reused.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dave Reisner 2014-05-09 19:55:41 -04:00 committed by Allan McRae
parent b929e74f2e
commit 7a5e41925f

View file

@ -286,7 +286,6 @@ static void curl_set_handle_opts(struct dload_payload *payload,
* to reset the handle's parameters for each time it's used. */ * to reset the handle's parameters for each time it's used. */
curl_easy_reset(curl); curl_easy_reset(curl);
curl_easy_setopt(curl, CURLOPT_URL, payload->fileurl); curl_easy_setopt(curl, CURLOPT_URL, payload->fileurl);
curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, error_buffer);
curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L); curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10L);
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
@ -478,12 +477,14 @@ static int curl_download_internal(struct dload_payload *payload,
_alpm_log(handle, ALPM_LOG_DEBUG, "response code: %ld\n", payload->respcode); _alpm_log(handle, ALPM_LOG_DEBUG, "response code: %ld\n", payload->respcode);
if(payload->respcode >= 400) { if(payload->respcode >= 400) {
payload->unlink_on_fail = 1; payload->unlink_on_fail = 1;
/* non-translated message is same as libcurl */ if(!payload->errors_ok) {
snprintf(error_buffer, sizeof(error_buffer), /* non-translated message is same as libcurl */
"The requested URL returned error: %ld", payload->respcode); snprintf(error_buffer, sizeof(error_buffer),
_alpm_log(handle, ALPM_LOG_ERROR, "The requested URL returned error: %ld", payload->respcode);
_("failed retrieving file '%s' from %s : %s\n"), _alpm_log(handle, ALPM_LOG_ERROR,
payload->remote_name, hostname, error_buffer); _("failed retrieving file '%s' from %s : %s\n"),
payload->remote_name, hostname, error_buffer);
}
goto cleanup; goto cleanup;
} }
break; break;