Message ID | 20200309201917.157342-1-anatol.pomozov@gmail.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | [pacman-dev] Implement _alpm_multi_download | expand |
Hi On Mon, Mar 9, 2020 at 1:19 PM Anatol Pomozov <anatol.pomozov@gmail.com> wrote: > > It is equivalent of _alpm_download but accepts list of payloads. > > 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 > + 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 >
On 10/3/20 6:20 am, Anatol Pomozov wrote: >> + 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? > I guess we never switched when pacman was made C99 back in 2007... configure.ac:AC_PROG_CC_C99 I have no objection to using stdbool.h. Though I'd prefer someone to spend the time converting things throughout the code base. On a similar note, someone could spend time doing GOTO_ERR conversions. A
(sending to the list - accidentally replied to Anatol directly) 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. > 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; > + 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) >
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) > >
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; + + 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)
It is equivalent of _alpm_download but accepts list of payloads. Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> --- lib/libalpm/dload.c | 50 +++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-)