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:
parent
db4258c1fd
commit
2d991a25ae
1 changed files with 59 additions and 40 deletions
|
@ -81,27 +81,11 @@ int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
||||||
return(0);
|
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;
|
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) {
|
while(lp) {
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
for(i = lp; i; i = i->next) {
|
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);
|
alpm_list_free(lp);
|
||||||
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
|
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 */
|
/* Remove needed packages (which break dependencies) from the target list */
|
||||||
while(lp != NULL) {
|
while(lp != NULL) {
|
||||||
alpm_list_t *i;
|
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);
|
alpm_list_free(lp);
|
||||||
lp = alpm_checkdeps(db, 1, trans->packages, NULL);
|
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 {
|
} else {
|
||||||
if(data) {
|
if(data) {
|
||||||
*data = lp;
|
*data = lp;
|
||||||
|
|
Loading…
Add table
Reference in a new issue