Hello On Mon, Mar 16, 2020 at 7:00 AM Allan McRae <allan@archlinux.org> wrote:
On 10/3/20 6:19 am, Anatol Pomozov wrote:
It is equivalent of _alpm_download but accepts list of payloads.
Expand the commit message to mention curl_multi_download_internal is just not functional at the moment.
Done.
Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> --- lib/libalpm/dload.c | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 7cd3e3a4..bec3ff5e 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -604,6 +604,16 @@ cleanup:
return ret; } + +static int curl_multi_download_internal(alpm_handle_t *handle, + alpm_list_t *payloads /* struct dload_payload */, + const char *localpath) +{ + (void)handle; + (void)payloads; + (void)localpath; + return 0; +} #endif
/** Download a file given by a URL to a local directory. @@ -640,10 +650,42 @@ int _alpm_multi_download(alpm_handle_t *handle, alpm_list_t *payloads /* struct dload_payload */, const char *localpath) { - (void)handle; - (void)payloads; - (void)localpath; - return 0; + if(handle->fetchcb == NULL) { +#ifdef HAVE_LIBCURL + return curl_multi_download_internal(handle, payloads, localpath); +#else
You need some (void)foo to get rid of unused variable warnings when building without libcurl.
(void)payloads; (void)localpath;
These 2 variables used below in the else{} branch. Thus there should not be any "unsed variable" warnings.
+ RET_ERR(handle, ALPM_ERR_EXTERNAL_DOWNLOAD, -1); +#endif + } else { + alpm_list_t *p; + for(p = payloads; p; p = p->next) { + struct dload_payload *payload = p->data; + alpm_list_t *s; + int success = 0; + + for(s = payload->servers; s; s = s->next) { + const char *server = s->data; + char *fileurl; + int ret; + + size_t len = strlen(server) + strlen(payload->filepath) + 2; + MALLOC(fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); + snprintf(fileurl, len, "%s/%s", server, payload->filepath); + + ret = handle->fetchcb(fileurl, localpath, payload->force); + free(fileurl); + + if (ret != -1) { + success = 1; + break; + } + } + if(!success && !payload->errors_ok) { + RET_ERR(handle, ALPM_ERR_EXTERNAL_DOWNLOAD, -1); + } + } + return 0; + } }
static char *filecache_find_url(alpm_handle_t *handle, const char *url)