summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-10-21 11:19:45 -0500
committerDan McGee <dan@archlinux.org>2011-10-21 19:29:31 -0500
commit0b155677cf127a2cd765f05125df727bb659b597 (patch)
tree6d073ebacd6e47d8adb663cc9bbb7ef06f66e7d7 /lib/libalpm
parent6f2faf16bac6976423124b77b0b134ebcfae6822 (diff)
sync: extract build_payload() method from find_dl_candidates
This is done by both the delta and regular file code, so we can extract a little helper method. Done mostly to satisfy my "why are we repeating code here" itch. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/dload.h2
-rw-r--r--lib/libalpm/sync.c32
2 files changed, 19 insertions, 15 deletions
diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h
index 158e0b77..9ab90b42 100644
--- a/lib/libalpm/dload.h
+++ b/lib/libalpm/dload.h
@@ -38,7 +38,7 @@ struct dload_payload {
int allow_resume;
int errors_ok;
int unlink_on_fail;
- const alpm_list_t *servers;
+ alpm_list_t *servers;
#ifdef HAVE_LIBCURL
CURLcode curlerr; /* last error produced by curl */
#endif
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index a5e8a5e7..04c557ba 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -790,6 +790,18 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
return 0;
}
+static struct dload_payload *build_payload(alpm_handle_t *handle,
+ const char *filename, size_t size, alpm_list_t *servers)
+{
+ struct dload_payload *payload;
+
+ CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(payload->remote_name, filename, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ payload->max_size = size;
+ payload->servers = servers;
+ return payload;
+}
+
static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t **deltas)
{
alpm_list_t *i;
@@ -814,14 +826,10 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t
for(dlts = delta_path; dlts; dlts = dlts->next) {
alpm_delta_t *delta = dlts->data;
if(delta->download_size != 0) {
- struct dload_payload *dpayload;
-
- CALLOC(dpayload, 1, sizeof(*dpayload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- STRDUP(dpayload->remote_name, delta->delta, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- dpayload->max_size = delta->download_size;
- dpayload->servers = repo->servers;
-
- *files = alpm_list_add(*files, dpayload);
+ struct dload_payload *payload = build_payload(
+ handle, delta->delta, delta->download_size, repo->servers);
+ ASSERT(payload, return -1);
+ *files = alpm_list_add(*files, payload);
}
/* keep a list of all the delta files for md5sums */
*deltas = alpm_list_add(*deltas, delta);
@@ -829,13 +837,9 @@ static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t
} else if(spkg->download_size != 0) {
struct dload_payload *payload;
-
ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
- CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- STRDUP(payload->remote_name, spkg->filename, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- payload->max_size = spkg->size;
- payload->servers = repo->servers;
-
+ payload = build_payload(handle, spkg->filename, spkg->size, repo->servers);
+ ASSERT(payload, return -1);
*files = alpm_list_add(*files, payload);
}
}