From: Jo-Philipp Wich Date: Tue, 15 Jan 2019 08:19:32 +0000 (+0100) Subject: libopkg: check installed reverse dependencies upon install/upgrade X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=89fe77cb119a24f728088320d66d51250a1f02ab;p=oweals%2Fopkg-lede.git libopkg: check installed reverse dependencies upon install/upgrade Signed-off-by: Jo-Philipp Wich --- diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index d2d919a..cc8ba94 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -40,25 +40,23 @@ #include "xsystem.h" #include "libbb/libbb.h" -static int satisfy_dependencies_for(pkg_t * pkg) +static pkg_vec_t * check_dependencies_for(pkg_t *pkg, bool silent) { - int i, err; - pkg_vec_t *depends = pkg_vec_alloc(); - pkg_t *dep; char **tmp, **unresolved = NULL, *prev = NULL; - int ndepends; + pkg_vec_t *depends = pkg_vec_alloc(); - ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends, - &unresolved); + pkg_hash_fetch_unsatisfied_dependencies(pkg, depends, &unresolved); if (unresolved) { - opkg_msg(ERROR, - "Cannot satisfy the following dependencies for %s:\n", - pkg->name); + if (silent == false) + opkg_msg(ERROR, + "Cannot satisfy the following dependencies for %s:\n", + pkg->name); tmp = unresolved; while (*unresolved) { if (!prev || strcmp(*unresolved, prev)) - opkg_message(ERROR, "\t%s\n", *unresolved); + if (silent == false) + opkg_message(ERROR, "\t%s\n", *unresolved); prev = *unresolved; unresolved++; } @@ -68,19 +66,30 @@ static int satisfy_dependencies_for(pkg_t * pkg) unresolved++; } free(tmp); + pkg_vec_free(depends); + return NULL; + } + + return depends; +} + +static int satisfy_dependencies_for(pkg_t * pkg) +{ + pkg_vec_t *depends; + int i, err; + pkg_t *dep; + + depends = check_dependencies_for(pkg, false); + + if (depends == NULL) { if (!conf->force_depends) { opkg_msg(INFO, "This could mean that your package list is out of date or that the packages\n" "mentioned above do not yet exist (try 'opkg update'). To proceed in spite\n" "of this problem try again with the '-force-depends' option.\n"); - pkg_vec_free(depends); - return -1; } - } - if (ndepends <= 0) { - pkg_vec_free(depends); - return 0; + return -1; } /* Mark packages as to-be-installed */ @@ -144,6 +153,67 @@ static int check_conflicts_for(pkg_t * pkg) return 0; } +static int check_reverse_depends_for(pkg_t *pkg, pkg_t *old_pkg) +{ + int err = 0; + int i, n_dependents; + abstract_pkg_t **dependents, *dependent; + pkg_vec_t *depends; + pkg_t *updated; + + opkg_msg(DEBUG, "Checking reverse depends for %s\n", old_pkg->name); + + n_dependents = pkg_has_installed_dependents(old_pkg, &dependents); + + /* pretend that old package does not exist */ + old_pkg->state_flag |= SF_IGNORE; + + if (n_dependents == 0) + goto out; + + while ((dependent = *dependents++) != NULL) { + if (dependent->state_status != SS_INSTALLED) + continue; + + if (dependent->pkgs == NULL) + continue; + + for (i = 0; i < dependent->pkgs->len; i++) { + if (dependent->pkgs->pkgs[i]->state_status != SS_INSTALLED) + continue; + + depends = check_dependencies_for(dependent->pkgs->pkgs[i], true); + if (depends == NULL) { +#if 0 + updated = pkg_hash_fetch_best_installation_candidate_by_name(dependent->pkgs->pkgs[i]->name); + depends = updated ? check_dependencies_for(updated, false) : NULL; + if (depends == NULL) { + opkg_msg(ERROR, "Package %s reverse dependency check failed\n", + pkg->name); + err = -1; + goto out; + } + else { + err = opkg_install_pkg(updated, 1); + if (err) + goto out; + } +#else + opkg_msg(ERROR, "Package %s reverse dependency check failed\n", pkg->name); + err = -1; + goto out; +#endif + } + + pkg_vec_free(depends); + } + } + +out: + old_pkg->state_flag &= ~SF_IGNORE; + return err; +} + static int update_file_ownership(pkg_t * new_pkg, pkg_t * old_pkg) { str_list_t *new_list, *old_list; @@ -1291,6 +1361,10 @@ int opkg_install_pkg(pkg_t * pkg, int from_upgrade) pkg->state_want = SW_INSTALL; if (old_pkg) { old_pkg->state_want = SW_DEINSTALL; /* needed for check_data_file_clashes of dependencies */ + + err = check_reverse_depends_for(pkg, old_pkg); + if (err) + return -1; } err = check_conflicts_for(pkg); diff --git a/libopkg/pkg.h b/libopkg/pkg.h index 600fc9e..f03bbb4 100644 --- a/libopkg/pkg.h +++ b/libopkg/pkg.h @@ -59,6 +59,7 @@ enum pkg_state_flag { SF_FILELIST_CHANGED = 128, /* needs filelist written */ SF_USER = 256, SF_NEED_DETAIL = 512, + SF_IGNORE = 1024, /* ignore this package in dependency checks */ SF_LAST_STATE_FLAG }; typedef enum pkg_state_flag pkg_state_flag_t; diff --git a/libopkg/pkg_depends.c b/libopkg/pkg_depends.c index 711283a..9fc7251 100644 --- a/libopkg/pkg_depends.c +++ b/libopkg/pkg_depends.c @@ -37,7 +37,8 @@ static int pkg_installed_and_constraint_satisfied(pkg_t * pkg, void *cdata) depend_t *depend = (depend_t *) cdata; if ((pkg->state_status == SS_INSTALLED || pkg->state_status == SS_UNPACKED) - && version_constraints_satisfied(depend, pkg)) + && version_constraints_satisfied(depend, pkg) + && !(pkg->state_flag & SF_IGNORE)) return 1; else return 0; @@ -46,7 +47,8 @@ static int pkg_installed_and_constraint_satisfied(pkg_t * pkg, void *cdata) static int pkg_constraint_satisfied(pkg_t * pkg, void *cdata) { depend_t *depend = (depend_t *) cdata; - if (version_constraints_satisfied(depend, pkg)) + if (version_constraints_satisfied(depend, pkg) + && !(pkg->state_flag & SF_IGNORE)) return 1; else return 0; diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c index 611f3b9..a474a18 100644 --- a/libopkg/pkg_hash.c +++ b/libopkg/pkg_hash.c @@ -357,12 +357,33 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg, /* now check for supported architecture */ { int max_count = 0; + int found_apkg = 0; /* count packages matching max arch priority and keep track of last one */ for (j = 0; j < vec->len; j++) { pkg_t *maybe = vec->pkgs[j]; arch_priority = pkg_get_arch_priority(maybe); + /* check if this package actually provides the requested + abstract package */ + found_apkg = 0; + provided_apkgs = pkg_get_ptr(maybe, PKG_PROVIDES); + + while (provided_apkgs && *provided_apkgs) { + if (!strcmp((*provided_apkgs)->name, apkg->name)) { + found_apkg = 1; + break; + } + provided_apkgs++; + } + + if (found_apkg == 0) { + opkg_msg(DEBUG, + "%s version=%s skipped since it does not provide %s\n", + maybe->name, pkg_get_string(maybe, PKG_VERSION), apkg->name); + continue; + } + opkg_msg(DEBUG, "%s arch=%s arch_priority=%d version=%s.\n", maybe->name, pkg_get_architecture(maybe),