From 1a04425fad2fbf88eb0cbb9648e7556a00dd2916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Ter=C3=A4s?= Date: Wed, 27 Jul 2011 22:10:44 +0300 Subject: [PATCH] solver: don't consider package that we can't have Packages that need (re-)installation but which are not available, are excluded now properly. --- src/solver.c | 28 ++++++++++++++++++++++++++-- test/basic7.expect | 0 test/basic7.test | 1 + 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/basic7.expect create mode 100644 test/basic7.test diff --git a/src/solver.c b/src/solver.c index 141b937..04d1036 100644 --- a/src/solver.c +++ b/src/solver.c @@ -35,9 +35,11 @@ struct apk_package_state { unsigned short conflicts; }; +#define APK_NAMESTF_AVAILABILITY_CHECKED 1 struct apk_name_state { struct list_head unsolved_list; struct apk_package *chosen; + unsigned short flags; unsigned short requirers; }; @@ -61,8 +63,6 @@ static int push_decision(struct apk_solver_state *ss, struct apk_package *pkg, static inline int pkg_available(struct apk_database *db, struct apk_package *pkg) { - if (pkg->ipkg != NULL) - return TRUE; if (pkg->installed_size == 0) return TRUE; if (pkg->filename != NULL) @@ -72,6 +72,29 @@ static inline int pkg_available(struct apk_database *db, struct apk_package *pkg return FALSE; } +static void prepare_name(struct apk_solver_state *ss, struct apk_name *name, + struct apk_name_state *ns) +{ + int i; + + if (ns->flags & APK_NAMESTF_AVAILABILITY_CHECKED) + return; + + for (i = 0; i < name->pkgs->num; i++) { + struct apk_package *pkg = name->pkgs->item[i]; + struct apk_package_state *ps = &ss->pkg_state[pkg->topology_sort]; + + /* if package is needed for (re-)install */ + if ((name->flags & APK_NAME_REINSTALL) || (pkg->ipkg == NULL)) { + /* and it's not available, we can't use it */ + if (!pkg_available(ss->db, pkg)) + ps->conflicts++; + } + } + + ns->flags |= APK_NAMESTF_AVAILABILITY_CHECKED; +} + static int foreach_dependency(struct apk_solver_state *ss, struct apk_dependency_array *deps, int (*func)(struct apk_solver_state *ss, struct apk_dependency *dep)) { @@ -276,6 +299,7 @@ static int apply_constraint(struct apk_solver_state *ss, struct apk_dependency * struct apk_package *pkg_best = NULL; int i, options = 0; + prepare_name(ss, name, ns); for (i = 0; i < name->pkgs->num; i++) { struct apk_package *pkg0 = name->pkgs->item[i]; struct apk_package_state *ps0 = &ss->pkg_state[pkg0->topology_sort]; diff --git a/test/basic7.expect b/test/basic7.expect new file mode 100644 index 0000000..e69de29 diff --git a/test/basic7.test b/test/basic7.test new file mode 100644 index 0000000..bd30545 --- /dev/null +++ b/test/basic7.test @@ -0,0 +1 @@ +--no-network --raw-repository basic.repo --installed basic.installed -u a