[pacman-dev] [PATCH] libalpm: process needed before group selection

morganamilo morganamilo at gmail.com
Sat Sep 22 16:24:33 UTC 2018


When --needed is used, up to date packages are now filtered out
before showing the group select.

Signed-off-by: morganamilo <morganamilo at gmail.com>
---

This patch set is currently incomplete. There is a problem where if every
package in the group is already installed you end up with the eror.
"error: target not found: groupname". Instead "there is nothing to do" should
be produced instead.

I'm unsure of how to solve this so I am submitting this for discussion.
Currently my idea is to have alpm_find_group_pkgs gain a new param `int *exists`
which the front end can then check instead of the length of the return. Or
instead the needed check could just be moved to the front end. Let me know
if theres a better way.

diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index b6ae7b72..f1c02417 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -270,6 +270,8 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
 	for(i = dbs; i; i = i->next) {
 		alpm_db_t *db = i->data;
 		alpm_group_t *grp = alpm_db_get_group(db, name);
+		alpm_handle_t *handle = db->handle;
+		alpm_trans_t *trans = handle->trans;
 
 		if(!grp) {
 			continue;
@@ -277,10 +279,26 @@ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs,
 
 		for(j = grp->packages; j; j = j->next) {
 			alpm_pkg_t *pkg = j->data;
+			alpm_pkg_t *local = _alpm_db_get_pkgfromcache(handle->db_local, pkg->name);
 
 			if(alpm_pkg_find(ignorelist, pkg->name)) {
 				continue;
 			}
+			if(local) {
+				const char *localpkgname = local->name;
+				const char *localpkgver = local->version;
+				int cmp = _alpm_pkg_compare_versions(pkg, local);
+
+				if(cmp == 0) {
+					if(trans != NULL && trans->flags & ALPM_TRANS_FLAG_NEEDED) {
+						/* with the NEEDED flag, packages up to date are not reinstalled */
+						_alpm_log(handle, ALPM_LOG_WARNING, _("%s-%s is up to date -- skipping\n"),
+								localpkgname, localpkgver);
+						ignorelist = alpm_list_add(ignorelist, pkg);
+						continue;
+					}
+				}
+			}
 			if(alpm_pkg_should_ignore(db->handle, pkg)) {
 				alpm_question_install_ignorepkg_t question = {
 					.type = ALPM_QUESTION_INSTALL_IGNOREPKG,
-- 
2.19.0


More information about the pacman-dev mailing list