[pacman-dev] [PATCH] call download progress callback for signatures

Andrew Gregory andrew.gregory.8 at gmail.com
Fri Apr 30 08:11:13 UTC 2021


pacman may not care about them, but other front-ends do.

Signed-off-by: Andrew Gregory <andrew.gregory.8 at gmail.com>
---
 lib/libalpm/dload.c   | 18 +++++++-----------
 src/pacman/callback.c | 12 ++++++++++++
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 935f5418..8fa46bb2 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -166,11 +166,6 @@ static int dload_progress_cb(void *file, curl_off_t dltotal, curl_off_t dlnow,
 	off_t current_size, total_size;
 	alpm_download_event_progress_t cb_data = {0};
 
-	/* do not print signature files progress bar */
-	if(payload->signature) {
-		return 0;
-	}
-
 	/* avoid displaying progress bar for redirects with a body */
 	if(payload->respcode >= 300) {
 		return 0;
@@ -669,7 +664,7 @@ cleanup:
 		unlink(payload->tempfile_name);
 	}
 
-	if(handle->dlcb && !payload->signature) {
+	if(handle->dlcb) {
 		alpm_download_event_completed_t cb_data = {0};
 		cb_data.total = bytes_dl;
 		cb_data.result = ret;
@@ -782,6 +777,12 @@ static int curl_add_payload(alpm_handle_t *handle, CURLM *curlm,
 
 	curl_easy_setopt(curl, CURLOPT_WRITEDATA, payload->localf);
 	curl_multi_add_handle(curlm, curl);
+
+	if(handle->dlcb) {
+		alpm_download_event_init_t cb_data = {.optional = payload->errors_ok};
+		handle->dlcb(handle->dlcb_ctx, payload->remote_name, ALPM_DOWNLOAD_INIT, &cb_data);
+	}
+
 	return 0;
 
 cleanup:
@@ -810,11 +811,6 @@ static int curl_download_internal(alpm_handle_t *handle,
 			struct dload_payload *payload = payloads->data;
 
 			if(curl_add_payload(handle, curlm, payload, localpath) == 0) {
-				if(handle->dlcb && !payload->signature) {
-					alpm_download_event_init_t cb_data = {.optional = payload->errors_ok};
-					handle->dlcb(handle->dlcb_ctx, payload->remote_name, ALPM_DOWNLOAD_INIT, &cb_data);
-				}
-
 				payloads = payloads->next;
 			} else {
 				/* The payload failed to start. Do not start any new downloads.
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index c3563af3..ae7e1bed 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -1070,10 +1070,22 @@ static void dload_complete_event(const char *filename, alpm_download_event_compl
 	}
 }
 
+static int strendswith(const char *haystack, const char *needle)
+{
+	size_t hlen = strlen(haystack), nlen = strlen(needle);
+	return hlen >= nlen && strcmp(haystack + hlen - nlen, needle) == 0;
+}
+
 /* Callback to handle display of download progress */
 void cb_download(void *ctx, const char *filename, alpm_download_event_type_t event, void *data)
 {
 	(void)ctx;
+
+	/* do not print signature files progress bar */
+	if(strendswith(filename, ".sig")) {
+		return;
+	}
+
 	if(event == ALPM_DOWNLOAD_INIT) {
 		dload_init_event(filename, data);
 	} else if(event == ALPM_DOWNLOAD_PROGRESS) {
-- 
2.31.1


More information about the pacman-dev mailing list