Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2020-04-18 19:00:49 -0700
committerAllan McRae <allan@archlinux.org>2020-05-09 11:58:39 +1000
commit0346e0eef224ab8ba22b659026ffdf2bfe95f3ae (patch)
tree992dfe0b373b222ca9e8e636fe117bce5a23479e
parentb96e0df4dceaa2677baa1a3563211950708d3e63 (diff)
Convert download packages logic to multiplexed API
Create a list of dload_payloads and pass it to the new _alpm_multi_* interface. Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
-rw-r--r--README11
-rw-r--r--lib/libalpm/alpm.h9
-rw-r--r--lib/libalpm/dload.c1
-rw-r--r--lib/libalpm/sync.c73
-rw-r--r--src/pacman/callback.c4
5 files changed, 36 insertions, 62 deletions
diff --git a/README b/README
index 6818ef70..f5bbaf02 100644
--- a/README
+++ b/README
@@ -655,3 +655,14 @@ API CHANGES BETWEEN 5.1 AND 5.2
- alpm_errno_t - added member ALPM_ERR_MISSING_CAPABILITY_SIGNATURES
- alpm_sync_newversion() replaced with alpm_sync_get_new_version() which
does not filter on any ALPM_DB_USAGE_*.
+
+
+API CHANGES BETWEEN 5.2 AND 6.0
+===============================
+
+[REMOVED]
+- ALPM_EVENT_PKGDOWNLOAD_START, ALPM_EVENT_PKGDOWNLOAD_DONE, ALPM_EVENT_PKGDOWNLOAD_FAILED
+
+[CHANGED]
+
+[ADDED]
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 534a8189..903e2fbc 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -414,15 +414,6 @@ typedef enum _alpm_event_type_t {
ALPM_EVENT_PKG_RETRIEVE_DONE,
/** Not all package files were successfully downloaded from a repository. */
ALPM_EVENT_PKG_RETRIEVE_FAILED,
- /** A file will be downloaded from a repository; See alpm_event_pkgdownload_t
- * for arguments */
- ALPM_EVENT_PKGDOWNLOAD_START,
- /** A file was downloaded from a repository; See alpm_event_pkgdownload_t
- * for arguments */
- ALPM_EVENT_PKGDOWNLOAD_DONE,
- /** A file failed to be downloaded from a repository; See
- * alpm_event_pkgdownload_t for arguments */
- ALPM_EVENT_PKGDOWNLOAD_FAILED,
/** Disk space usage will be computed for a package. */
ALPM_EVENT_DISKSPACE_START,
/** Disk space usage was computed for a package. */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 9ab0e5c4..13aa4086 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -952,7 +952,6 @@ static int curl_multi_download_internal(alpm_handle_t *handle,
}
payloads = payloads->next;
- // TODO: report that download has started
} else {
// the payload failed to start, do not start any new downloads just wait until
// active one complete.
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 855ca69c..f329de10 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -726,47 +726,13 @@ static int find_dl_candidates(alpm_handle_t *handle, alpm_list_t **files)
return 0;
}
-static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload,
- const char *cachedir)
-{
- alpm_event_pkgdownload_t event = {
- .type = ALPM_EVENT_PKGDOWNLOAD_START,
- .file = payload->remote_name
- };
- const alpm_list_t *server;
-
- payload->handle = handle;
- payload->allow_resume = 1;
-
- EVENT(handle, &event);
- for(server = payload->servers; server; server = server->next) {
- const char *server_url = server->data;
- size_t len;
-
- /* print server + filename into a buffer */
- len = strlen(server_url) + strlen(payload->remote_name) + 2;
- MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
-
- if(_alpm_download(payload, cachedir, NULL, NULL) != -1) {
- event.type = ALPM_EVENT_PKGDOWNLOAD_DONE;
- EVENT(handle, &event);
- return 0;
- }
- _alpm_dload_payload_reset_for_retry(payload);
- }
-
- event.type = ALPM_EVENT_PKGDOWNLOAD_FAILED;
- EVENT(handle, &event);
- return -1;
-}
-
static int download_files(alpm_handle_t *handle)
{
const char *cachedir;
alpm_list_t *i, *files = NULL;
int errors = 0;
alpm_event_t event;
+ alpm_list_t *payloads = NULL;
cachedir = _alpm_filecache_setup(handle);
handle->trans->state = STATE_DOWNLOADING;
@@ -814,26 +780,37 @@ static int download_files(alpm_handle_t *handle)
event.type = ALPM_EVENT_PKG_RETRIEVE_START;
EVENT(handle, &event);
- event.type = ALPM_EVENT_PKG_RETRIEVE_DONE;
for(i = files; i; i = i->next) {
const alpm_pkg_t *pkg = i->data;
- struct dload_payload payload = {0};
-
- STRDUP(payload.remote_name, pkg->filename, GOTO_ERR(handle, ALPM_ERR_MEMORY, finish));
- payload.servers = pkg->origin_data.db->servers;
- payload.max_size = pkg->size;
-
- if(download_single_file(handle, &payload, cachedir) == -1) {
- errors++;
- event.type = ALPM_EVENT_PKG_RETRIEVE_FAILED;
- _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));
- }
- _alpm_dload_payload_reset(&payload);
+ struct dload_payload *payload = NULL;
+
+ CALLOC(payload, 1, sizeof(*payload), GOTO_ERR(handle, ALPM_ERR_MEMORY, finish));
+ STRDUP(payload->remote_name, pkg->filename, FREE(payload); GOTO_ERR(handle, ALPM_ERR_MEMORY, finish));
+ STRDUP(payload->filepath, pkg->filename,
+ FREE(payload->remote_name); FREE(payload);
+ GOTO_ERR(handle, ALPM_ERR_MEMORY, finish));
+ payload->max_size = pkg->size;
+ payload->servers = pkg->origin_data.db->servers;
+ payload->handle = handle;
+ payload->allow_resume = 1;
+
+ payloads = alpm_list_add(payloads, payload);
+ }
+ event.type = ALPM_EVENT_PKG_RETRIEVE_DONE;
+ if(_alpm_multi_download(handle, payloads, cachedir) == -1) {
+ errors++;
+ event.type = ALPM_EVENT_PKG_RETRIEVE_FAILED;
+ _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));
}
EVENT(handle, &event);
}
finish:
+ if(payloads) {
+ alpm_list_free_inner(payloads, (alpm_list_fn_free)_alpm_dload_payload_reset);
+ FREELIST(payloads);
+ }
+
if(files) {
alpm_list_free(files);
}
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index c2e516ec..25909e02 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -405,10 +405,6 @@ void cb_event(alpm_event_t *event)
case ALPM_EVENT_DISKSPACE_DONE:
case ALPM_EVENT_HOOK_DONE:
case ALPM_EVENT_HOOK_RUN_DONE:
- /* we can safely ignore those as well */
- case ALPM_EVENT_PKGDOWNLOAD_START:
- case ALPM_EVENT_PKGDOWNLOAD_DONE:
- case ALPM_EVENT_PKGDOWNLOAD_FAILED:
/* nothing */
break;
}