[pacman-dev] [PATCH 08/14] Make recursive removal consider optdepends

Benedikt Morbach benedikt.morbach at googlemail.com
Wed Nov 23 10:51:22 EST 2011


Signed-off-by: Benedikt Morbach <benedikt.morbach at googlemail.com>
---
 lib/libalpm/deps.c             |   18 +++++++++++++++++-
 test/pacman/tests/remove053.py |   15 +++++++++++++++
 test/pacman/tests/remove054.py |   14 ++++++++++++++
 test/pacman/tests/remove055.py |   20 ++++++++++++++++++++
 4 files changed, 66 insertions(+), 1 deletions(-)
 create mode 100644 test/pacman/tests/remove053.py
 create mode 100644 test/pacman/tests/remove054.py
 create mode 100644 test/pacman/tests/remove055.py

diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 12d7156..83bc619 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -85,6 +85,19 @@ static int _alpm_dep_edge(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2)
 	return 0;
 }
 
+/* Does pkg1 optdepend on pkg2, ie. does pkg2 satisfy a optional dependency of pkg1? */
+static int _alpm_optdep_edge(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2)
+{
+	alpm_list_t *i;
+	for(i = alpm_pkg_get_optdepends(pkg1); i; i = i->next) {
+		alpm_optdepend_t *optdep = i->data;
+		if(_alpm_depcmp(pkg2, optdep->depend)) {
+			return 1;
+		}
+	}
+	return 0;
+}
+
 /* Convert a list of alpm_pkg_t * to a graph structure,
  * with a edge for each dependency.
  * Returns a list of vertices (one vertex = one package)
@@ -554,6 +567,9 @@ static int can_remove_package(alpm_db_t *db, alpm_pkg_t *pkg,
 		if(_alpm_dep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) {
 			return 0;
 		}
+		if(_alpm_optdep_edge(lpkg, pkg) && !_alpm_pkg_find(targets, lpkg->name)) {
+			return 0;
+		}
 	}
 
 	/* it's ok to remove */
@@ -583,7 +599,7 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t *targs, int include_explicit)
 		alpm_pkg_t *pkg = i->data;
 		for(j = _alpm_db_get_pkgcache(db); j; j = j->next) {
 			alpm_pkg_t *deppkg = j->data;
-			if(_alpm_dep_edge(pkg, deppkg)
+			if((_alpm_dep_edge(pkg, deppkg) || _alpm_optdep_edge(pkg, deppkg))
 					&& can_remove_package(db, deppkg, targs, include_explicit)) {
 				alpm_pkg_t *copy;
 				_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding '%s' to the targets\n",
diff --git a/test/pacman/tests/remove053.py b/test/pacman/tests/remove053.py
new file mode 100644
index 0000000..52d86dd
--- /dev/null
+++ b/test/pacman/tests/remove053.py
@@ -0,0 +1,15 @@
+self.description = "-Rs test (unneeded optdeps)"
+
+p1 = pmpkg("dummy")
+p1.optdepends = ["dep: for foobar"]
+self.addpkg2db("local", p1)
+
+p2 = pmpkg("dep")
+p2.reason = 1
+self.addpkg2db("local", p2)
+
+self.args = "-Rs %s" % p1.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=dummy")
+self.addrule("!PKG_EXIST=dep")
diff --git a/test/pacman/tests/remove054.py b/test/pacman/tests/remove054.py
new file mode 100644
index 0000000..0653449
--- /dev/null
+++ b/test/pacman/tests/remove054.py
@@ -0,0 +1,14 @@
+self.description = "-Rss test (unneeded optdeps, explicit)"
+
+p1 = pmpkg("dummy")
+p1.optdepends = ["dep: for foobar"]
+self.addpkg2db("local", p1)
+
+p2 = pmpkg("dep")
+self.addpkg2db("local", p2)
+
+self.args = "-Rss %s" % p1.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=dummy")
+self.addrule("!PKG_EXIST=dep")
diff --git a/test/pacman/tests/remove055.py b/test/pacman/tests/remove055.py
new file mode 100644
index 0000000..e8134ad
--- /dev/null
+++ b/test/pacman/tests/remove055.py
@@ -0,0 +1,20 @@
+self.description = "-Rs test (needed optdeps)"
+
+p1 = pmpkg("dummy")
+p1.optdepends = ["dep: for foobar"]
+self.addpkg2db("local", p1)
+
+p2 = pmpkg("keep")
+p2.optdepends = ["dep: for baz"]
+self.addpkg2db("local", p2)
+
+p3 = pmpkg("dep")
+p3.reason = 1
+self.addpkg2db("local", p3)
+
+self.args = "-Rs %s" % p1.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("!PKG_EXIST=dummy")
+self.addrule("PKG_EXIST=keep")
+self.addrule("PKG_EXIST=dep")
-- 
1.7.7.3



More information about the pacman-dev mailing list