From e63366ae5e701d8e9ae33144f68e8786b092a468 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Sun, 18 Nov 2007 18:45:46 +0100 Subject: New remove option : -u / --unneeded (FS#6505). With --unneeded option 'pacman -R' doesn't stop in case of dependency error; it removes the needed-dependency targets from the target-list instead. See also: http://archlinux.org/pipermail/pacman-dev/2007-October/009653.html . The patch also adds a new causingpkg field to pmdepmissing_t which indicates the to-be-removed package which would cause a dependency break. This is needed, because miss->depend.name may be a provision. miss->causingpkg will be useful in -R dependency error messages too. [Xavier: renamed inducer to causingpkg, removed the _alpm_pkgname_pkg_cmp helper function as requested by Aaron. This might be added by a further commit. Other small cleanups, updated manpage and bash completion.] Signed-off-by: Chantry Xavier --- lib/libalpm/remove.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/remove.c') 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); } -- cgit v1.2.3-54-g00ecf