[pacman-dev] [PATCH v3] libalpm: fix 404 pages ending up inside package downloads

morganamilo morganamilo at archlinux.org
Fri May 21 18:32:18 UTC 2021


Previously successfull but non 200 responses would still be written to
disk before trying the next server. This would lead to the next download
resuming with the html response in the file.

---

v2: ensure allow_resume is passed to callback
Signed-off-by: morganamilo <morganamilo at archlinux.org>
---
 lib/libalpm/dload.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 2d8b4d6d..734132d3 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -404,7 +404,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat
 }
 
 /* Return 0 if retry was successful, -1 otherwise */
-static int curl_retry_next_server(CURLM *curlm, CURL *curl, struct dload_payload *payload)
+static int curl_retry_next_server(CURLM *curlm, CURL *curl, struct dload_payload *payload, int allow_resume)
 {
 	const char *server;
 	size_t len;
@@ -428,10 +428,9 @@ static int curl_retry_next_server(CURLM *curlm, CURL *curl, struct dload_payload
 	MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
 	snprintf(payload->fileurl, len, "%s/%s", server, payload->filepath);
 
-
 	fflush(payload->localf);
 
-	if(payload->allow_resume && stat(payload->tempfile_name, &st) == 0) {
+	if(allow_resume && stat(payload->tempfile_name, &st) == 0) {
 		/* a previous partial download exists, resume from end of file. */
 		payload->tempfile_openmode = "ab";
 		curl_easy_setopt(curl, CURLOPT_RESUME_FROM_LARGE, (curl_off_t)st.st_size);
@@ -449,7 +448,7 @@ static int curl_retry_next_server(CURLM *curlm, CURL *curl, struct dload_payload
 
 	if(handle->dlcb && !payload->signature) {
 		alpm_download_event_retry_t cb_data;
-		cb_data.resume = payload->allow_resume;
+		cb_data.resume = allow_resume;
 		handle->dlcb(handle->dlcb_ctx, payload->remote_name, ALPM_DOWNLOAD_RETRY, &cb_data);
 	}
 
@@ -510,7 +509,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
 							payload->remote_name, hostname, payload->error_buffer);
 					server_soft_error(handle, payload->fileurl);
 				}
-				if(curl_retry_next_server(curlm, curl, payload) == 0) {
+				if(curl_retry_next_server(curlm, curl, payload, 0) == 0) {
 					(*active_downloads_num)++;
 					return 2;
 				} else {
@@ -537,7 +536,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
 					_("failed retrieving file '%s' from %s : %s\n"),
 					payload->remote_name, hostname, payload->error_buffer);
 			server_hard_error(handle, payload->fileurl);
-			if(curl_retry_next_server(curlm, curl, payload) == 0) {
+			if(curl_retry_next_server(curlm, curl, payload, payload->allow_resume) == 0) {
 				(*active_downloads_num)++;
 				return 2;
 			} else {
@@ -556,7 +555,7 @@ static int curl_check_finished_download(CURLM *curlm, CURLMsg *msg,
 						"failed retrieving file '%s' from %s : %s\n",
 						payload->remote_name, hostname, payload->error_buffer);
 			}
-			if(curl_retry_next_server(curlm, curl, payload) == 0) {
+			if(curl_retry_next_server(curlm, curl, payload, payload->allow_resume) == 0) {
 				(*active_downloads_num)++;
 				return 2;
 			} else {
-- 
2.31.1


More information about the pacman-dev mailing list