/** Find group members across a list of databases. * If a member exists in several databases, only the first database is used. * IgnorePkg is also handled. * @param dbs the list of alpm_db_t * * @param name the name of the group * @return the list of alpm_pkg_t * (caller is responsible for alpm_list_free) */ alpm_list_t SYMEXPORT *alpm_find_group_pkgs(alpm_list_t *dbs, const char *name) { alpm_list_t *i, *j, *pkgs = NULL, *ignorelist = NULL; for(i = dbs; i; i = i->next) { alpm_db_t *db = i->data; alpm_group_t *grp = alpm_db_get_group(db, name); if(!grp) continue; for(j = grp->packages; j; j = j->next) { alpm_pkg_t *pkg = j->data; if(alpm_pkg_find(ignorelist, pkg->name)) { continue; } if(_alpm_pkg_should_ignore(db->handle, pkg)) { ignorelist = alpm_list_add(ignorelist, pkg); int install = 0; QUESTION(db->handle, ALPM_QUESTION_INSTALL_IGNOREPKG, pkg, NULL, NULL, &install); if(!install) continue; } if(!alpm_pkg_find(pkgs, pkg->name)) { pkgs = alpm_list_add(pkgs, pkg); } } } alpm_list_free(ignorelist); return pkgs; }
static int remove_target(const char *target) { alpm_pkg_t *pkg; alpm_db_t *db_local = alpm_get_localdb(config->handle); alpm_list_t *p; if((pkg = alpm_db_get_pkg(db_local, target)) != NULL) { if(alpm_remove_pkg(config->handle, pkg) == -1) { pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target, alpm_strerror(alpm_errno(config->handle))); return -1; } config->explicit_removes = alpm_list_add(config->explicit_removes, pkg); return 0; } /* fallback to group */ alpm_group_t *grp = alpm_db_get_group(db_local, target); if(grp == NULL) { pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), target); return -1; } for(p = grp->packages; p; p = alpm_list_next(p)) { pkg = p->data; if(alpm_remove_pkg(config->handle, pkg) == -1) { pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target, alpm_strerror(alpm_errno(config->handle))); return -1; } config->explicit_removes = alpm_list_add(config->explicit_removes, pkg); } return 0; }
static alpm_list_t *search_groups(alpm_list_t *dbs, alpm_list_t *groupnames) { alpm_list_t *i, *j, *packages = NULL; for (i = groupnames; i; i = i->next) { for (j = dbs; j; j = j->next) { alpm_group_t *grp = alpm_db_get_group(j->data, i->data); if (grp != NULL) { packages = alpm_list_join(packages, alpm_list_copy(grp->packages)); } } } return packages; }