From ea1f09e2112cf5c98d45c973af0bcc34fb3f43f1 Mon Sep 17 00:00:00 2001 From: pixdamix@gmail.com Date: Thu, 22 Nov 2012 04:17:43 -0500 Subject: Fix dependency issues for preinst scripts There is a problem with dependency order when installing packages. The key problem revolves around the satisfy_dependencies_for() function which is called from opkg_install_pkg just before the installation (and preinst) happens. The satisfy_dependencies_for() function calls pkg_hash_fetch_unsatisfied_dependencies() which will only return packages which were previously not marked as *going* to be installed at some point. For the purposes of opkg_install_pkg() we really need to know which dependencies haven't been installed yet. This patch adds pkg_hash_fetch_satisfied_dependencies() which returns a list of package dependencies. We can then directly check the status of these and ensure any hard dependencies (not suggestions or recommendations) are installed before returning. Consider the situation (where -> means 'depends on'): X -> A,E A -> B,E E -> B B -> C Currently X would install A and E. When installing A the packages B, E and C would be marked as "to install". When the package B is considered the second time (as a dependency of E rather than A), it would install straight away even though C was not currently installed, just marked as needing to be installed. The patch changes the behaviour so B can't install until C really is installed. This change is required to run the postinst scripts in the correct order. Signed-off-by: Martin Jansa git-svn-id: http://opkg.googlecode.com/svn/trunk@638 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- (limited to 'libopkg/opkg_install.c') diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index 3925f58..6ed67d2 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -77,6 +77,27 @@ satisfy_dependencies_for(pkg_t *pkg) if (ndepends <= 0) { pkg_vec_free(depends); + depends = pkg_hash_fetch_satisfied_dependencies(pkg); + + for (i = 0; i < depends->len; i++) { + dep = depends->pkgs[i]; + /* The package was uninstalled when we started, but another + dep earlier in this loop may have depended on it and pulled + it in, so check first. */ + if ((dep->state_status != SS_INSTALLED) && (dep->state_status != SS_UNPACKED)) { + opkg_msg(DEBUG2,"Calling opkg_install_pkg.\n"); + err = opkg_install_pkg(dep, 0); + /* mark this package as having been automatically installed to + * satisfy a dependency */ + dep->auto_installed = 1; + if (err) { + pkg_vec_free(depends); + return err; + } + } + } + + pkg_vec_free(depends); return 0; } -- cgit v0.9.1