diff options
Diffstat (limited to 'lib/libalpm')
-rw-r--r-- | lib/libalpm/alpm.h | 4 | ||||
-rw-r--r-- | lib/libalpm/deps.c | 22 | ||||
-rw-r--r-- | lib/libalpm/deps.h | 4 | ||||
-rw-r--r-- | lib/libalpm/remove.c | 26 |
4 files changed, 49 insertions, 7 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 027b1fee..bcc344d8 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -281,7 +281,8 @@ typedef enum _pmtransflag_t { PM_TRANS_FLAG_NOCONFLICTS = 0x800, PM_TRANS_FLAG_PRINTURIS = 0x1000, PM_TRANS_FLAG_NEEDED = 0x2000, - PM_TRANS_FLAG_ALLEXPLICIT = 0x4000 + PM_TRANS_FLAG_ALLEXPLICIT = 0x4000, + PM_TRANS_FLAG_UNNEEDED = 0x8000 } pmtransflag_t; /* Transaction Events */ @@ -378,6 +379,7 @@ alpm_list_t *alpm_deptest(pmdb_t *db, alpm_list_t *targets); const char *alpm_miss_get_target(const pmdepmissing_t *miss); pmdepend_t *alpm_miss_get_dep(pmdepmissing_t *miss); +const char *alpm_miss_get_causingpkg(const pmdepmissing_t *miss); alpm_list_t *alpm_checkdbconflicts(pmdb_t *db_local); diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 5c63e9d6..c08c59e9 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -68,7 +68,8 @@ static void _alpm_graph_free(void *data) free(graph); } -pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep) +pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep, + const char *causingpkg) { pmdepmissing_t *miss; @@ -78,6 +79,7 @@ pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep) STRDUP(miss->target, target, RET_ERR(PM_ERR_MEMORY, NULL)); miss->depend = _alpm_dep_dup(dep); + STRDUP(miss->causingpkg, causingpkg, RET_ERR(PM_ERR_MEMORY, NULL)); return(miss); } @@ -86,6 +88,7 @@ void _alpm_depmiss_free(pmdepmissing_t *miss) { _alpm_dep_free(miss->depend); FREE(miss->target); + FREE(miss->causingpkg); FREE(miss); } @@ -298,7 +301,7 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps, _alpm_log(PM_LOG_DEBUG, "checkdeps: missing dependency '%s' for package '%s'\n", missdepstring, alpm_pkg_get_name(tp)); free(missdepstring); - miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend); + miss = _alpm_depmiss_new(alpm_pkg_get_name(tp), depend, ""); baddeps = alpm_list_add(baddeps, miss); } } @@ -311,17 +314,18 @@ alpm_list_t SYMEXPORT *alpm_checkdeps(pmdb_t *db, int reversedeps, pmpkg_t *lp = i->data; for(j = alpm_pkg_get_depends(lp); j; j = j->next) { pmdepend_t *depend = j->data; + pmpkg_t *causingpkg = alpm_list_find(modified, depend, satisfycmp); /* we won't break this depend, if it is already broken, we ignore it */ /* 1. check upgrade list for satisfiers */ /* 2. check dblist for satisfiers */ - if(alpm_list_find(modified, depend, satisfycmp) && + if(causingpkg && !alpm_list_find(upgrade, depend, satisfycmp) && !alpm_list_find(dblist, depend, satisfycmp)) { char *missdepstring = alpm_dep_get_string(depend); _alpm_log(PM_LOG_DEBUG, "checkdeps: transaction would break '%s' dependency of '%s'\n", missdepstring, alpm_pkg_get_name(lp)); free(missdepstring); - miss = _alpm_depmiss_new(lp->name, depend); + miss = _alpm_depmiss_new(lp->name, depend, alpm_pkg_get_name(causingpkg)); baddeps = alpm_list_add(baddeps, miss); } } @@ -675,6 +679,16 @@ const char SYMEXPORT *alpm_miss_get_target(const pmdepmissing_t *miss) return(miss->target); } +const char SYMEXPORT *alpm_miss_get_causingpkg(const pmdepmissing_t *miss) +{ + ALPM_LOG_FUNC; + + /* Sanity checks */ + ASSERT(miss != NULL, return(NULL)); + + return miss->causingpkg; +} + pmdepend_t SYMEXPORT *alpm_miss_get_dep(pmdepmissing_t *miss) { ALPM_LOG_FUNC; diff --git a/lib/libalpm/deps.h b/lib/libalpm/deps.h index fdbfebed..439a92a2 100644 --- a/lib/libalpm/deps.h +++ b/lib/libalpm/deps.h @@ -37,6 +37,7 @@ struct __pmdepend_t { struct __pmdepmissing_t { char *target; pmdepend_t *depend; + char *causingpkg; /* this is used in case of remove dependency error only */ }; /* Graphs */ @@ -51,7 +52,8 @@ struct __pmgraph_t { void _alpm_dep_free(pmdepend_t *dep); pmdepend_t *_alpm_dep_dup(const pmdepend_t *dep); -pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep); +pmdepmissing_t *_alpm_depmiss_new(const char *target, pmdepend_t *dep, + const char *causinpkg); void _alpm_depmiss_free(pmdepmissing_t *miss); alpm_list_t *_alpm_sortbydeps(alpm_list_t *targets, pmtranstype_t mode); void _alpm_recursedeps(pmdb_t *db, alpm_list_t *targs, int include_explicit); diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 10a055bb..a0c308fb 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -124,11 +124,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); } + } else if (trans->flags & PM_TRANS_FLAG_UNNEEDED) { + /* Remove needed packages (which break dependencies) from the target list */ + while(lp != NULL) { + alpm_list_t *i; + for(i = lp; i; i = i->next) { + pmdepmissing_t *miss = (pmdepmissing_t *)i->data; + void *vpkg; + pmpkg_t *pkg; + pmpkg_t *dummy = _alpm_pkg_new(miss->causingpkg, NULL); + trans->packages = alpm_list_remove(trans->packages, dummy, + _alpm_pkg_cmp, &vpkg); + _alpm_pkg_free(dummy); + pkg = vpkg; + if(pkg) { + _alpm_log(PM_LOG_WARNING, "removing %s from the target-list\n", + alpm_pkg_get_name(pkg)); + _alpm_pkg_free(pkg); + } + } + alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free); + alpm_list_free(lp); + lp = alpm_checkdeps(db, 1, trans->packages, NULL); + } } else { if(data) { *data = lp; } else { - FREELIST(lp); + alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free); + alpm_list_free(lp); } RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1); } |