From 43a265f3b6585e9a97d4793bd117418dfac446e0 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 3 Jun 2013 18:35:00 +0200 Subject: [PATCH] Prompt user to install optdepends. --- src/pacman/sync.c | 110 +++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 93 insertions(+), 17 deletions(-) diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 2093029..c94ce5d 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -37,6 +37,8 @@ #include "package.h" #include "conf.h" +static int process_optdepends(alpm_pkg_t *pkg, int error); + static int unlink_verbose(const char *pathname, int ignore_missing) { int ret = unlink(pathname); @@ -569,31 +571,19 @@ static int process_pkg(alpm_pkg_t *pkg) } } config->explicit_adds = alpm_list_add(config->explicit_adds, pkg); + if(process_optdepends(pkg, ret)) { + pm_printf(ALPM_LOG_WARNING, _("error processing optdepends: %s\n"), alpm_pkg_get_name(pkg)); + } return 0; } -static int process_group(alpm_list_t *dbs, const char *group, int error) +static int process_optionals(alpm_list_t *pkgs) { + int count = alpm_list_count(pkgs); int ret = 0; alpm_list_t *i; - alpm_list_t *pkgs = alpm_find_group_pkgs(dbs, group); - int count = alpm_list_count(pkgs); - - if(!count) { - pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group); - return 1; - } - - if(error) { - /* we already know another target errored. there is no reason to prompt the - * user here; we already validated the group name so just move on since we - * won't actually be installing anything anyway. */ - goto cleanup; - } if(config->print == 0) { - colon_printf(_("There are %d members in group %s:\n"), count, - group); select_display(pkgs); char *array = malloc(count); if(!array) { @@ -634,6 +624,92 @@ cleanup: return ret; } +static int process_optdepends(alpm_pkg_t *pkg, int error) +{ + alpm_list_t *optdeps = alpm_pkg_get_optdepends(pkg); + alpm_list_t *pkgs = NULL; + alpm_list_t *db_remote; + alpm_db_t *db_local; + alpm_list_t *i; + int count = 0; + + db_remote = alpm_get_syncdbs(config->handle); + db_local = alpm_get_localdb(config->handle); + + for(i = optdeps; i; i = i->next) { + /* check if package is already installed */ + if(alpm_db_get_pkg(db_local, ((alpm_depend_t *)i->data)->name) == NULL) { + count++; + } + } + + if(count == 0) { + return 0; + } + + for(i = optdeps; i; i = i->next) { + const char *name = ((alpm_depend_t *)i->data)->name; + if (alpm_db_get_pkg(db_local, name) != NULL) { + continue; + } + + alpm_pkg_t *dep = alpm_find_dbs_satisfier(config->handle, db_remote, name); + + if(dep != NULL) { + pkgs = alpm_list_add(pkgs, dep); + pm_printf(ALPM_LOG_DEBUG, _("safisfier found: %s\n"), name); + } else { + pm_printf(ALPM_LOG_WARNING, _("no satisfier for optdep found: %s\n"), name); + } + } + + count = alpm_list_count(pkgs); + if(!count) { + pm_printf(ALPM_LOG_WARNING, _("no optdepends could be satisfied: %s\n"), + alpm_pkg_get_name(pkg)); + return 0; + } + + if(error) { + /* we already know another target errored. there is no reason to prompt the + * user here; we already validated the group name so just move on since we + * won't actually be installing anything anyway. */ + return 1; + } + + if(config->print == 0) { + colon_printf(_("There are %d optdepends for package %s:\n"), count, + alpm_pkg_get_name(pkg)); + } + + return process_optionals(pkgs); +} + +static int process_group(alpm_list_t *dbs, const char *group, int error) +{ + alpm_list_t *pkgs = alpm_find_group_pkgs(dbs, group); + int count = alpm_list_count(pkgs); + + if(!count) { + pm_printf(ALPM_LOG_ERROR, _("target not found: %s\n"), group); + return 1; + } + + if(error) { + /* we already know another target errored. there is no reason to prompt the + * user here; we already validated the group name so just move on since we + * won't actually be installing anything anyway. */ + return 1; + } + + if(config->print == 0) { + colon_printf(_("There are %d members in group %s:\n"), count, + group); + } + + return process_optionals(pkgs); +} + static int process_targname(alpm_list_t *dblist, const char *targname, int error) { -- 1.8.3