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 <shiningxc@gmail.com>
This commit is contained in:
Nagy Gabor 2007-11-18 18:45:46 +01:00 committed by Chantry Xavier
parent e81dec9b8c
commit e63366ae5e
8 changed files with 78 additions and 7 deletions

View File

@ -187,6 +187,7 @@ _pacman ()
dbonly) mod="${mod}k" ;;
nosave) mod="${mod}n" ;;
recursive) mod="${mod}s" ;;
unneeded) mod="${mod}u" ;;
esac ;;
*) toparse="${a}" ;;
esac
@ -243,6 +244,7 @@ _pacman ()
-k --dbonly \
-n --nosave \
-s --recursive \
-u --unneeded \
--config \
--logfile \
--noconfirm \

View File

@ -233,6 +233,11 @@ Remove Options[[RO]]
to a backwards '\--sync' operation, and helps keep a clean system without
orphans.
*-u, \--unneeded*::
Removes the targets that are not required by any other packages.
This is mostly useful when removing a group without using the '-c' option,
to avoid breaking any dependencies.
Sync Options[[SO]]
------------------

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);
}

View File

@ -0,0 +1,19 @@
self.description = "-Ru test"
lp1 = pmpkg("pkg1")
lp1.requiredby = [ "pkg3" ]
self.addpkg2db("local", lp1)
lp2 = pmpkg("pkg2")
self.addpkg2db("local", lp2)
lp3 = pmpkg("pkg3")
lp3.depends = [ "pkg1" ]
self.addpkg2db("local", lp3)
self.args = "-Ru pkg1 pkg2"
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
self.addrule("!PKG_EXIST=pkg2")
self.addrule("PKG_EXIST=pkg3")

View File

@ -90,6 +90,7 @@ static void usage(int op, const char * const myname)
printf(_(" -k, --dbonly only remove database entry, do not remove files\n"));
printf(_(" -n, --nosave remove configuration files as well\n"));
printf(_(" -s, --recursive remove dependencies also (that won't break packages)\n"));
printf(_(" -u, --unneeded remove unneeded packages (that won't break packages)\n"));
} else if(op == PM_OP_UPGRADE) {
printf("%s: %s {-U --upgrade} [%s] <%s>\n", str_usg, myname, str_opt, str_file);
printf("%s:\n", str_opt);
@ -330,6 +331,7 @@ static int parseargs(int argc, char *argv[])
{"unrequired", no_argument, 0, 't'},
{"upgrades", no_argument, 0, 'u'},
{"sysupgrade", no_argument, 0, 'u'},
{"unneeded", no_argument, 0, 'u'},
{"verbose", no_argument, 0, 'v'},
{"downloadonly", no_argument, 0, 'w'},
{"refresh", no_argument, 0, 'y'},
@ -472,6 +474,7 @@ static int parseargs(int argc, char *argv[])
case 'u':
config->op_s_upgrade = 1;
config->op_q_upgrade = 1;
config->flags |= PM_TRANS_FLAG_UNNEEDED;
break;
case 'v': (config->verbose)++; break;
case 'w':