summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2011-07-27 22:10:44 +0300
committerTimo Teräs <timo.teras@iki.fi>2011-07-27 22:10:44 +0300
commit1a04425fad2fbf88eb0cbb9648e7556a00dd2916 (patch)
treeba5b66ae20398047fc31d50381fdc9adcf4587e4 /src
parentad45a6de178e8680a325dbdd0da5f637fdd0efd6 (diff)
downloadapk-tools-1a04425fad2fbf88eb0cbb9648e7556a00dd2916.tar.gz
apk-tools-1a04425fad2fbf88eb0cbb9648e7556a00dd2916.tar.bz2
apk-tools-1a04425fad2fbf88eb0cbb9648e7556a00dd2916.tar.xz
apk-tools-1a04425fad2fbf88eb0cbb9648e7556a00dd2916.zip
solver: don't consider package that we can't have
Packages that need (re-)installation but which are not available, are excluded now properly.
Diffstat (limited to 'src')
-rw-r--r--src/solver.c28
1 files changed, 26 insertions, 2 deletions
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];