mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
sync_commit: refactor out file downloads
This part is almost completely self-contained, except building the list of delta filenames that we use later to check their md5sums. Refactor it into a static method so we can bring most of the code in sync_commit closer to the method name. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
225acbbff1
commit
2df1534b78
@ -687,18 +687,12 @@ static int test_md5sum(pmtrans_t *trans, const char *filepath,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
static int download_files(pmtrans_t *trans, alpm_list_t **deltas)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j, *k;
|
const char *cachedir;
|
||||||
alpm_list_t *files = NULL, *deltas = NULL;
|
alpm_list_t *i, *j;
|
||||||
size_t numtargs, current = 0, replaces = 0;
|
alpm_list_t *files = NULL;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
const char *cachedir = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
|
|
||||||
cachedir = _alpm_filecache_setup();
|
cachedir = _alpm_filecache_setup();
|
||||||
trans->state = STATE_DOWNLOADING;
|
trans->state = STATE_DOWNLOADING;
|
||||||
@ -731,26 +725,18 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
alpm_list_t *delta_path = spkg->delta_path;
|
alpm_list_t *delta_path = spkg->delta_path;
|
||||||
if(delta_path) {
|
if(delta_path) {
|
||||||
/* using deltas */
|
/* using deltas */
|
||||||
alpm_list_t *dlts = NULL;
|
alpm_list_t *dlts;
|
||||||
|
|
||||||
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
for(dlts = delta_path; dlts; dlts = dlts->next) {
|
||||||
pmdelta_t *d = dlts->data;
|
pmdelta_t *delta = dlts->data;
|
||||||
|
if(delta->download_size != 0) {
|
||||||
if(d->download_size != 0) {
|
files = alpm_list_add(files, strdup(delta->delta));
|
||||||
/* add the delta filename to the download list if needed */
|
|
||||||
files = alpm_list_add(files, strdup(d->delta));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* keep a list of all the delta files for md5sums */
|
/* keep a list of all the delta files for md5sums */
|
||||||
deltas = alpm_list_add(deltas, d);
|
*deltas = alpm_list_add(*deltas, delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else if(spkg->download_size != 0) {
|
||||||
/* not using deltas */
|
files = alpm_list_add(files, strdup(fname));
|
||||||
if(spkg->download_size != 0) {
|
|
||||||
/* add the filename to the download list if needed */
|
|
||||||
files = alpm_list_add(files, strdup(fname));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -760,15 +746,17 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
|
EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL);
|
||||||
for(j = files; j; j = j->next) {
|
for(j = files; j; j = j->next) {
|
||||||
const char *filename = j->data;
|
const char *filename = j->data;
|
||||||
for(k = current->servers; k; k = k->next) {
|
alpm_list_t *server;
|
||||||
const char *server = k->data;
|
for(server = current->servers; server; server = server->next) {
|
||||||
|
const char *server_url = server->data;
|
||||||
char *fileurl;
|
char *fileurl;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int ret;
|
||||||
|
|
||||||
/* print server + filename into a buffer */
|
/* print server + filename into a buffer */
|
||||||
len = strlen(server) + strlen(filename) + 2;
|
len = strlen(server_url) + strlen(filename) + 2;
|
||||||
CALLOC(fileurl, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
|
CALLOC(fileurl, len, sizeof(char), RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
snprintf(fileurl, len, "%s/%s", server, filename);
|
snprintf(fileurl, len, "%s/%s", server_url, filename);
|
||||||
|
|
||||||
ret = _alpm_download(fileurl, cachedir, 0, 1, 0);
|
ret = _alpm_download(fileurl, cachedir, 0, 1, 0);
|
||||||
FREE(fileurl);
|
FREE(fileurl);
|
||||||
@ -779,15 +767,15 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FREELIST(files);
|
||||||
if(errors) {
|
if(errors) {
|
||||||
_alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
|
_alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
|
||||||
current->treename);
|
current->treename);
|
||||||
if(pm_errno == 0) {
|
if(pm_errno == 0) {
|
||||||
pm_errno = PM_ERR_RETRIEVE;
|
pm_errno = PM_ERR_RETRIEVE;
|
||||||
}
|
}
|
||||||
goto error;
|
return -1;
|
||||||
}
|
}
|
||||||
FREELIST(files);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,6 +789,24 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
if(handle->totaldlcb) {
|
if(handle->totaldlcb) {
|
||||||
handle->totaldlcb(0);
|
handle->totaldlcb(0);
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
||||||
|
{
|
||||||
|
alpm_list_t *i;
|
||||||
|
alpm_list_t *deltas = NULL;
|
||||||
|
size_t numtargs, current = 0, replaces = 0;
|
||||||
|
int errors = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
|
|
||||||
|
if(download_files(trans, &deltas)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
/* if we have deltas to work with */
|
/* if we have deltas to work with */
|
||||||
if(handle->usedelta && deltas) {
|
if(handle->usedelta && deltas) {
|
||||||
@ -969,7 +975,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
FREELIST(files);
|
|
||||||
alpm_list_free(deltas);
|
alpm_list_free(deltas);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user