[pacman-dev] libalpm: download signatures with a fetch callback

Message ID 1eb71e41-5bb1-19eb-4426-609c7a61cf1f@manjaro.org
State New
Headers show
Series [pacman-dev] libalpm: download signatures with a fetch callback | expand

Commit Message

Guillaume Benoit April 30, 2021, 9:51 a.m. UTC
Remove an unwanted break and download signatures when using a custom fetch callback.

---
  lib/libalpm/dload.c | 43 +++++++++++++++++++++++++++++++++++++------
  1 file changed, 37 insertions(+), 6 deletions(-)

  					snprintf(fileurl, len, "%s/%s", server, payload->filepath);
   					ret = handle->fetchcb(fileurl, localpath, payload->force);
-					free(fileurl);
   					if (ret != -1) {
-						success = 1;
-						break;
+						/* Let's check if client requested downloading accompanion *.sig file */
+						if(payload->download_signature) {
+							char *sig_fileurl;
+
+							size_t sig_len = strlen(fileurl) + 5;
+							MALLOC(sig_fileurl, sig_len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+							snprintf(sig_fileurl, sig_len, "%s.sig", fileurl);
+
+							ret = handle->fetchcb(sig_fileurl, localpath, payload->force);
+
+							free(sig_fileurl);
+						}
+						if (ret != -1) {
+							success = 1;
+							break;
+						}
  					}
+					free(fileurl);
  				}
  			}
  			if(!success && !payload->errors_ok) {

Patch

diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index a4c42f8d..6f33451a 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -877,9 +877,26 @@  int _alpm_download(alpm_handle_t *handle,
  			int success = 0;
   			if(payload->fileurl) {
-				if (handle->fetchcb(payload->fileurl, localpath, payload->force) != -1) {
-					success = 1;
-					break;
+				int ret;
+
+				ret = handle->fetchcb(payload->fileurl, localpath, payload->force);
+
+				if (ret != -1) {
+					/* Let's check if client requested downloading accompanion *.sig file */
+					if(payload->download_signature) {
+						char *sig_fileurl;
+
+						size_t sig_len = strlen(payload->fileurl) + 5;
+						MALLOC(sig_fileurl, sig_len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+						snprintf(sig_fileurl, sig_len, "%s.sig", payload->fileurl);
+
+						ret = handle->fetchcb(sig_fileurl, localpath, payload->force);
+
+						free(sig_fileurl);
+					}
+					if (ret != -1) {
+						success = 1;
+					}
  				}
  			} else {
  				for(s = payload->servers; s; s = s->next) {
@@ -892,12 +909,26 @@  int _alpm_download(alpm_handle_t *handle,