Clean up pacman/sync.c and organize it a bit
Re-add some checks for a valid target list. In addition, move variable declarations to the most local scope possible, which should help in finding errors that were previously uncaught. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
5e774d72b0
commit
620a811f91
2 changed files with 42 additions and 13 deletions
|
@ -288,9 +288,10 @@ static int query_foreign(void)
|
||||||
alpm_list_t *sync_dbs = NULL;
|
alpm_list_t *sync_dbs = NULL;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
|
||||||
|
/* ensure we have at least one valid sync db set up */
|
||||||
sync_dbs = alpm_option_get_syncdbs();
|
sync_dbs = alpm_option_get_syncdbs();
|
||||||
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
||||||
fprintf(stderr, _("error: no usable package repositories configured.\n"));
|
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -448,38 +448,53 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
|
||||||
|
|
||||||
int pacman_sync(alpm_list_t *targets)
|
int pacman_sync(alpm_list_t *targets)
|
||||||
{
|
{
|
||||||
int confirm = 0;
|
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
alpm_list_t *packages, *data = NULL, *i, *j, *k, *sync_dbs;
|
alpm_list_t *sync_dbs = NULL;
|
||||||
|
|
||||||
sync_dbs = alpm_option_get_syncdbs();
|
|
||||||
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
|
||||||
fprintf(stderr, _("error: no usable package repositories configured.\n"));
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* clean the cache */
|
||||||
if(config->op_s_clean) {
|
if(config->op_s_clean) {
|
||||||
return(sync_cleancache(config->op_s_clean));
|
return(sync_cleancache(config->op_s_clean));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ensure we have at least one valid sync db set up */
|
||||||
|
sync_dbs = alpm_option_get_syncdbs();
|
||||||
|
if(sync_dbs == NULL || alpm_list_count(sync_dbs) == 0) {
|
||||||
|
pm_printf(PM_LOG_ERROR, _("no usable package repositories configured.\n"));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* First: operations that do not require targets */
|
||||||
|
|
||||||
|
/* search for a package */
|
||||||
if(config->op_s_search) {
|
if(config->op_s_search) {
|
||||||
return(sync_search(sync_dbs, targets));
|
return(sync_search(sync_dbs, targets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* look for groups */
|
||||||
if(config->group) {
|
if(config->group) {
|
||||||
return(sync_group(config->group, sync_dbs, targets));
|
return(sync_group(config->group, sync_dbs, targets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get package info */
|
||||||
if(config->op_s_info) {
|
if(config->op_s_info) {
|
||||||
return(sync_info(sync_dbs, targets));
|
return(sync_info(sync_dbs, targets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* get a listing of files in sync DBs */
|
||||||
if(config->op_q_list) {
|
if(config->op_q_list) {
|
||||||
return(sync_list(sync_dbs, targets));
|
return(sync_list(sync_dbs, targets));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* don't proceed here unless we have an operation that doesn't require
|
||||||
|
* a target list */
|
||||||
|
if(targets == NULL && !(config->op_s_sync || config->op_s_upgrade)) {
|
||||||
|
pm_printf(PM_LOG_ERROR, _("no targets specified (use -h for help)\n"));
|
||||||
|
return(1);
|
||||||
|
}
|
||||||
|
|
||||||
/* Step 1: create a new transaction... */
|
/* Step 1: create a new transaction... */
|
||||||
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt, cb_trans_conv, cb_trans_progress) == -1) {
|
if(alpm_trans_init(PM_TRANS_TYPE_SYNC, config->flags, cb_trans_evt,
|
||||||
|
cb_trans_conv, cb_trans_progress) == -1) {
|
||||||
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to init transaction (%s)\n"),
|
||||||
alpm_strerror(pm_errno));
|
alpm_strerror(pm_errno));
|
||||||
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
if(pm_errno == PM_ERR_HANDLE_LOCK) {
|
||||||
|
@ -500,6 +515,8 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(config->op_s_upgrade) {
|
if(config->op_s_upgrade) {
|
||||||
|
alpm_list_t *pkgs, *i;
|
||||||
|
|
||||||
printf(_(":: Starting full system upgrade...\n"));
|
printf(_(":: Starting full system upgrade...\n"));
|
||||||
alpm_logaction(_("starting full system upgrade"));
|
alpm_logaction(_("starting full system upgrade"));
|
||||||
if(alpm_trans_sysupgrade() == -1) {
|
if(alpm_trans_sysupgrade() == -1) {
|
||||||
|
@ -512,8 +529,8 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
* this can prevent some of the "syntax error" problems users can have
|
* this can prevent some of the "syntax error" problems users can have
|
||||||
* when sysupgrade'ing with an older version of pacman.
|
* when sysupgrade'ing with an older version of pacman.
|
||||||
*/
|
*/
|
||||||
data = alpm_trans_get_pkgs();
|
pkgs = alpm_trans_get_pkgs();
|
||||||
for(i = data; i; i = alpm_list_next(i)) {
|
for(i = pkgs; i; i = alpm_list_next(i)) {
|
||||||
pmsyncpkg_t *sync = alpm_list_getdata(i);
|
pmsyncpkg_t *sync = alpm_list_getdata(i);
|
||||||
pmpkg_t *spkg = alpm_sync_get_pkg(sync);
|
pmpkg_t *spkg = alpm_sync_get_pkg(sync);
|
||||||
/* TODO pacman name should probably not be hardcoded. In addition, we
|
/* TODO pacman name should probably not be hardcoded. In addition, we
|
||||||
|
@ -549,12 +566,16 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
alpm_list_t *i;
|
||||||
|
|
||||||
/* process targets */
|
/* process targets */
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
char *targ = alpm_list_getdata(i);
|
char *targ = alpm_list_getdata(i);
|
||||||
if(alpm_trans_addtarget(targ) == -1) {
|
if(alpm_trans_addtarget(targ) == -1) {
|
||||||
pmgrp_t *grp = NULL;
|
pmgrp_t *grp = NULL;
|
||||||
int found=0;
|
int found=0;
|
||||||
|
alpm_list_t *j;
|
||||||
|
|
||||||
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
|
if(pm_errno == PM_ERR_TRANS_DUP_TARGET) {
|
||||||
/* just ignore duplicate targets */
|
/* just ignore duplicate targets */
|
||||||
continue;
|
continue;
|
||||||
|
@ -571,6 +592,8 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
pmdb_t *db = alpm_list_getdata(j);
|
pmdb_t *db = alpm_list_getdata(j);
|
||||||
grp = alpm_db_readgrp(db, targ);
|
grp = alpm_db_readgrp(db, targ);
|
||||||
if(grp) {
|
if(grp) {
|
||||||
|
alpm_list_t *k;
|
||||||
|
|
||||||
found++;
|
found++;
|
||||||
printf(_(":: group %s:\n"), targ);
|
printf(_(":: group %s:\n"), targ);
|
||||||
/* remove dupe entries in case a package exists in multiple repos */
|
/* remove dupe entries in case a package exists in multiple repos */
|
||||||
|
@ -618,10 +641,12 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Step 2: "compute" the transaction based on targets and flags */
|
/* Step 2: "compute" the transaction based on targets and flags */
|
||||||
|
alpm_list_t *data;
|
||||||
if(alpm_trans_prepare(&data) == -1) {
|
if(alpm_trans_prepare(&data) == -1) {
|
||||||
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to prepare transaction (%s)\n"),
|
||||||
alpm_strerror(pm_errno));
|
alpm_strerror(pm_errno));
|
||||||
switch(pm_errno) {
|
switch(pm_errno) {
|
||||||
|
alpm_list_t *i;
|
||||||
case PM_ERR_UNSATISFIED_DEPS:
|
case PM_ERR_UNSATISFIED_DEPS:
|
||||||
for(i = data; i; i = alpm_list_next(i)) {
|
for(i = data; i; i = alpm_list_next(i)) {
|
||||||
pmdepmissing_t *miss = alpm_list_getdata(i);
|
pmdepmissing_t *miss = alpm_list_getdata(i);
|
||||||
|
@ -658,7 +683,7 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
packages = alpm_trans_get_pkgs();
|
alpm_list_t *packages = alpm_trans_get_pkgs();
|
||||||
if(packages == NULL) {
|
if(packages == NULL) {
|
||||||
/* nothing to do: just exit without complaining */
|
/* nothing to do: just exit without complaining */
|
||||||
printf(_(" local database is up to date\n"));
|
printf(_(" local database is up to date\n"));
|
||||||
|
@ -666,6 +691,8 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
|
if(!(alpm_trans_get_flags() & PM_TRANS_FLAG_PRINTURIS)) {
|
||||||
|
int confirm;
|
||||||
|
|
||||||
display_targets(packages);
|
display_targets(packages);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
|
@ -699,6 +726,7 @@ int pacman_sync(alpm_list_t *targets)
|
||||||
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
|
fprintf(stderr, _("error: failed to commit transaction (%s)\n"),
|
||||||
alpm_strerror(pm_errno));
|
alpm_strerror(pm_errno));
|
||||||
switch(pm_errno) {
|
switch(pm_errno) {
|
||||||
|
alpm_list_t *i;
|
||||||
case PM_ERR_FILE_CONFLICTS:
|
case PM_ERR_FILE_CONFLICTS:
|
||||||
for(i = data; i; i = alpm_list_next(i)) {
|
for(i = data; i; i = alpm_list_next(i)) {
|
||||||
pmconflict_t *conflict = alpm_list_getdata(i);
|
pmconflict_t *conflict = alpm_list_getdata(i);
|
||||||
|
|
Loading…
Add table
Reference in a new issue