[pacman-dev] [PATCH] Implement _alpm_multi_download

Anatol Pomozov anatol.pomozov at gmail.com
Mon Mar 9 20:20:59 UTC 2020


Hi

On Mon, Mar 9, 2020 at 1:19 PM Anatol Pomozov <anatol.pomozov at gmail.com> wrote:
>
> It is equivalent of _alpm_download but accepts list of payloads.
>
> Signed-off-by: Anatol Pomozov <anatol.pomozov at 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
> +               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;

I would prefer to use <stdbool.h> here. But it seems pacman does not
use it anywhere. Is there any objection to start using bool type?

> +
> +                       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)
> --
> 2.25.1
>


More information about the pacman-dev mailing list