remove.c: refactor into functions

Pulled two loops out of _alpm_remove_prepare and gave them their own
functions.

Signed-off-by: K. Piche <kevin@archlinux.org>
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
K. Piche 2008-04-04 23:02:23 -04:00 committed by Dan McGee
parent db4258c1fd
commit 2d991a25ae

View file

@ -81,27 +81,11 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
return(0);
}
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
alpm_list_t *lp)
{
alpm_list_t *lp;
ALPM_LOG_FUNC;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
/* skip all checks if we are doing this removal as part of an upgrade */
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
return(0);
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
while(lp) {
alpm_list_t *i;
for(i = lp; i; i = i->next) {
@ -122,7 +106,13 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
alpm_list_free(lp);
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
}
} else if (trans->flags & PM_TRANS_FLAG_UNNEEDED) {
}
static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
alpm_list_t *lp)
{
ALPM_LOG_FUNC;
/* Remove needed packages (which break dependencies) from the target list */
while(lp != NULL) {
alpm_list_t *i;
@ -143,6 +133,35 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
alpm_list_free(lp);
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
}
}
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
{
alpm_list_t *lp;
ALPM_LOG_FUNC;
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
/* skip all checks if we are doing this removal as part of an upgrade */
if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
return(0);
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
remove_prepare_cascade(trans, db, lp);
} else if (trans->flags & PM_TRANS_FLAG_UNNEEDED) {
/* Remove needed packages (which would break dependencies)
* from the target list */
remove_prepare_keep_needed(trans, db, lp);
} else {
if(data) {
*data = lp;