pkg_hash: don't swallow dependencies
authorDaniel Golle <daniel@makrotopia.org>
Mon, 2 Nov 2020 14:35:12 +0000 (14:35 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Mon, 2 Nov 2020 16:56:11 +0000 (16:56 +0000)
Checking for unsatisfiable dependencies had the unwanted side-effect of
making opkg skip **all** dependencies. Fix that by clearing the
dependencies_checked flag after calling to
pkg_hash_fetch_unsatisfied_dependencies(), similar to how it is also
done in opkg.c.

Fixes: 8769c75 ("pkg_hash: don't suggest incompatible packages")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libopkg/pkg_hash.c

index 6715ebd112da012c12cdc552d271b96bde0505c9..f3ff4bafd1b70985172051fa8a7f0c28fd358d4f 100644 (file)
@@ -274,6 +274,37 @@ int pkg_hash_load_package_details(void)
        return 0;
 }
 
+static int
+pkg_hash_check_unresolved(const pkg_t *maybe)
+{
+       char **unresolved = NULL;
+       char **tmp;
+       pkg_vec_t *depends, *all;
+       int i, res = 0;
+
+       depends = pkg_vec_alloc();
+       pkg_hash_fetch_unsatisfied_dependencies(maybe, depends, &unresolved);
+
+       if (unresolved) {
+               res = 1;
+               tmp = unresolved;
+               while (tmp)
+                       free(*(tmp++));
+               free(unresolved);
+       }
+       pkg_vec_free(depends);
+
+       /* clear depenacy checked marks, left by pkg_hash_fetch_unsatisfied_dependencies */
+       all = pkg_vec_alloc();
+       pkg_hash_fetch_available(all);
+       for (i = 0; i < all->len; i++) {
+               all->pkgs[i]->parent->dependencies_checked = 0;
+       }
+       pkg_vec_free(all);
+
+       return res;
+}
+
 pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                                                  int (*constraint_fcn) (pkg_t *
                                                                         pkg,
@@ -376,24 +407,13 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                                   they show up twice sometimes. */
                                if ((arch_priority > 0)
                                    &&
-                                   (!pkg_vec_contains(matching_pkgs, maybe))) {
-                                       char **unresolved = NULL;
-                                       pkg_vec_t *depends = pkg_vec_alloc();
-                                       pkg_hash_fetch_unsatisfied_dependencies(maybe, depends,
-                                               &unresolved);
-
-                                       if (!unresolved) {
-                                               max_count++;
-                                               abstract_pkg_vec_insert(matching_apkgs,
-                                                                       maybe->parent);
-                                               pkg_vec_insert(matching_pkgs, maybe);
-                                       } else {
-                                               char **tmp = unresolved;
-                                               while (tmp)
-                                                       free(*(tmp++));
-                                               free(unresolved);
-                                       }
-                                       pkg_vec_free(depends);
+                                   (!pkg_vec_contains(matching_pkgs, maybe))
+                                   &&
+                                   (!pkg_hash_check_unresolved(maybe))) {
+                                       max_count++;
+                                       abstract_pkg_vec_insert(matching_apkgs,
+                                                               maybe->parent);
+                                       pkg_vec_insert(matching_pkgs, maybe);
                                }
                        }