From patchwork Tue Apr 14 04:40:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anatol Pomozov X-Patchwork-Id: 1585 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 42A6018303F35 for ; Tue, 14 Apr 2020 04:41:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_LOW=-0.7,SPF_HELO_NONE=0.001,SUBJ_OBFU_PUNCT_FEW=0.748, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=no autolearn_force=no version=3.4.4 X-Spam-BL-Results: [127.0.9.1] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Tue, 14 Apr 2020 04:41:25 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 83B731AF2D6D61; Tue, 14 Apr 2020 04:41:22 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 1688C1AF2D6D5A; Tue, 14 Apr 2020 04:41:22 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VZjuHq4T Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 094612B324; Tue, 14 Apr 2020 04:41:22 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VZjuHq4T Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 34F8A2B2B8 for ; Tue, 14 Apr 2020 04:41:19 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Tue, 14 Apr 2020 04:41:19 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 4B7491AF2D6D56 for ; Tue, 14 Apr 2020 04:41:18 +0000 (UTC) Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Tue, 14 Apr 2020 04:41:18 +0000 (UTC) Received: by mail-pl1-x643.google.com with SMTP id n24so1486040plp.13 for ; Mon, 13 Apr 2020 21:41:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8Nw2Aa9AyzWruAmbEMgMs3wqyiAaSLDAgw+Q6ut70ek=; b=VZjuHq4Tm4mE8hITNfz1UBrWjf5cffv1wIhqv7r+0ZMfNkrQTHz+vp0krYpgM59oW5 E5lNURio8XkIhjJdGciIb7bDf7kA4u460sFQ6S/gVCSaS+PBmy9V2961Rmf6gyWZ5Vg9 pT+R1crrL7ke4BrrVQYpJYee7ifSPwDR+qYyqEkMZBR1omPNq5YZASOmm6BTRFXITLB0 rk5rtLzDV5DKoMRloG2wUUmZmAOc1Igtp1JbQaXqon8TenbWbgG+nScLXStLmjdQCIPS 5BmnIrhImA/wSM0H9NcVsuXs1UpzFkjSm2VYQ8BY0guiqVcZfNvbvV7bu3R+Ez+VSydg 4GeQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=8Nw2Aa9AyzWruAmbEMgMs3wqyiAaSLDAgw+Q6ut70ek=; b=CseynYg+m0FtG0RLyHJr99kOwcea/V93ZhDdASJuQrPPDZP5a6i3lm/HQq+grzKapC B1/CInF9C92sRpA39QKV759x+uKRATfxqbpEQJkm97WdDwnG5V2UsUXm8dCJiXn2NLSg oS13ETX+F+oicMRLiAeRiTJfznkp/Hb4+d52EwC+sv//YDDBtJDST3h4I6ZQUiHjvKXk kRE2QwnrTheTBMMWiRkjnltWLt2ZAloUvwkjkuCj9mQSZRqYKe9a9eZ5L5u4r3m1oPwG UFa87UWUr3/tWcO4gi1e8Q6TtWrBff8nyqPCYCl0YKqh0ETFKqcyxVJ2ghBfoHZ6r5YJ gY/g== X-Gm-Message-State: AGi0PubGjS35iiZzpAMRQfFjsO22dFIATF/rmSmsCK+JHYpY1gCDt4BZ T+GMzSgW69+22EufPawr/Drhdcd0mbw= X-Google-Smtp-Source: APiQypK8lKsZgdc2r6CHPaEitPJJONURlxRSgdgr+2SeFI/SPu5/BNz30IvVsY2l/7N7HlBZgX0/Lw== X-Received: by 2002:a17:90b:4d07:: with SMTP id mw7mr26556654pjb.103.1586839274924; Mon, 13 Apr 2020 21:41:14 -0700 (PDT) Received: from wolf.hsd1.ca.comcast.net ([2601:646:8500:a860:2efd:a1ff:febf:a363]) by smtp.gmail.com with ESMTPSA id 189sm9882004pfg.170.2020.04.13.21.41.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2020 21:41:14 -0700 (PDT) From: Anatol Pomozov To: pacman-dev@archlinux.org Date: Mon, 13 Apr 2020 21:40:54 -0700 Message-Id: <20200414044054.110942-1-anatol.pomozov@gmail.com> X-Mailer: git-send-email 2.26.0 MIME-Version: 1.0 Subject: [pacman-dev] [PATCH v2] Implement _alpm_multi_download X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" It is an equivalent of _alpm_download but accepts a list of payloads. curl_multi_download_internal() is a stub at this moment and will be implemented in the later commits of this patch series. Signed-off-by: Anatol Pomozov --- 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 4c81b11f..a413792a 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -598,6 +598,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. @@ -634,10 +644,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; + + 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)