libopkg: clean up handling of unresolved dependencies
authorDaniel Golle <daniel@makrotopia.org>
Tue, 3 Nov 2020 04:09:21 +0000 (04:09 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Tue, 3 Nov 2020 04:37:36 +0000 (04:37 +0000)
Drastically improves performance, back to the level seen before
the previous commit.

Fixes: 3837489 ("libopkg: work-around yet another dependency checking problem")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Paul Spooren <mail@aparcar.org>
libopkg/opkg.c
libopkg/opkg_install.c
libopkg/pkg.h
libopkg/pkg_depends.c
libopkg/pkg_depends.h
libopkg/pkg_hash.c

index 3583488780221b6fc566aa3b39ce378950a0503b..85ab5a05347d284586755473839d1c581cfc6315 100644 (file)
@@ -238,7 +238,7 @@ opkg_install_package(const char *package_name,
        /* find dependancies and download them */
        deps = pkg_vec_alloc();
        /* this function does not return the original package, so we insert it later */
-       pkg_hash_fetch_unsatisfied_dependencies(new, deps, &unresolved);
+       pkg_hash_fetch_unsatisfied_dependencies(new, deps, &unresolved, 0);
        if (unresolved) {
                char **tmp = unresolved;
                opkg_msg(ERROR, "Couldn't satisfy the following dependencies"
index 27c9484cfb8189e42cbc073eaa14a67c71c3507a..62db9650f411845c9fa05aa92e5297b6e20bf80d 100644 (file)
@@ -49,7 +49,7 @@ static int satisfy_dependencies_for(pkg_t * pkg)
        int ndepends;
 
        ndepends = pkg_hash_fetch_unsatisfied_dependencies(pkg, depends,
-                                                          &unresolved);
+                                                          &unresolved, 0);
 
        if (unresolved) {
                opkg_msg(ERROR,
index 28998f39fdc9405d22c530676ac92ee19b55c722..bc0e030e800142e26fc174756a3d9f586c602538 100644 (file)
@@ -113,8 +113,8 @@ struct abstract_pkg {
        abstract_pkg_vec_t *provided_by;
        abstract_pkg_vec_t *replaced_by;
 
-       int dependencies_checked:2;
-       int prev_dependencies_checked:2;
+       char dependencies_checked;
+       char pre_dependencies_checked;
        pkg_state_status_t state_status:4;
        pkg_state_flag_t state_flag:11;
 };
index 3abdcd38c4436468bed71929c7114ceb3dfacdc9..a95fceb86a011183dc8ff42fac242021fc66395a 100644 (file)
@@ -55,7 +55,7 @@ static int pkg_constraint_satisfied(pkg_t * pkg, void *cdata)
 /* returns ndependencies or negative error value */
 int
 pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
-                                       char ***unresolved)
+                                       char ***unresolved, int pre_check)
 {
        pkg_t *satisfier_entry_pkg;
        int i, j, k;
@@ -63,6 +63,7 @@ pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
        char **the_lost;
        abstract_pkg_t *ab_pkg;
        compound_depend_t *compound_depend;
+       char *check;
 
        /*
         * this is a setup to check for redundant/cyclic dependency checks,
@@ -73,11 +74,19 @@ pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
                *unresolved = NULL;
                return 0;
        }
-       if (ab_pkg->dependencies_checked) {     /* avoid duplicate or cyclic checks */
+
+       if(pre_check) {
+               check = &ab_pkg->pre_dependencies_checked;
+       } else {
+               check = &ab_pkg->dependencies_checked;
+       }
+
+       if (*check) {   /* avoid duplicate or cyclic checks */
                *unresolved = NULL;
                return 0;
        } else {
-               ab_pkg->dependencies_checked = 1;       /* mark it for subsequent visits */
+               /* mark it for subsequent visits */
+               *check = 1;
        }
 
        compound_depend = pkg_get_ptr(pkg, PKG_DEPENDS);
@@ -117,14 +126,14 @@ pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
                                                pkg_t *pkg_scout = test_vec->pkgs[k];
                                                /* not installed, and not already known about? */
                                                if ((pkg_scout->state_want != SW_INSTALL)
-                                                   && !pkg_scout->parent->dependencies_checked
+                                                   && !(pre_check ? pkg_scout->parent->pre_dependencies_checked : pkg_scout->parent->dependencies_checked)
                                                    && !is_pkg_in_pkg_vec(unsatisfied, pkg_scout)) {
                                                        char **newstuff = NULL;
                                                        int rc;
                                                        pkg_vec_t *tmp_vec = pkg_vec_alloc();
                                                        /* check for not-already-installed dependencies */
                                                        rc = pkg_hash_fetch_unsatisfied_dependencies(
-                                                               pkg_scout, tmp_vec, &newstuff);
+                                                               pkg_scout, tmp_vec, &newstuff, pre_check);
                                                        if (newstuff == NULL) {
                                                                int m;
                                                                int ok = 1;
@@ -251,7 +260,7 @@ pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * unsatisfied,
                                            !is_pkg_in_pkg_vec(unsatisfied, satisfier_entry_pkg))
                                        {
                                                pkg_hash_fetch_unsatisfied_dependencies(
-                                                       satisfier_entry_pkg, unsatisfied, &newstuff);
+                                                       satisfier_entry_pkg, unsatisfied, &newstuff, pre_check);
                                                pkg_vec_insert(unsatisfied, satisfier_entry_pkg);
                                                the_lost = merge_unresolved(the_lost, newstuff);
                                                if (newstuff)
index af897b239d037cc608b96484731b5e4c55e16792..de1dabf104f364ef12cb96e4de8e7490daf8674b 100644 (file)
@@ -89,7 +89,7 @@ char *pkg_depend_str(pkg_t * pkg, int index);
 void buildDependedUponBy(pkg_t * pkg, abstract_pkg_t * ab_pkg);
 int version_constraints_satisfied(depend_t * depends, pkg_t * pkg);
 int pkg_hash_fetch_unsatisfied_dependencies(pkg_t * pkg, pkg_vec_t * depends,
-                                           char ***unresolved);
+                                           char ***unresolved, int pre_check);
 pkg_vec_t *pkg_hash_fetch_conflicts(pkg_t * pkg);
 int pkg_dependence_satisfiable(depend_t * depend);
 const char *constraint_to_str(enum version_constraint c);
index 6eeedec70610be4b5ef150f12cddafbf4c0cea92..6b408729d8553020082999b6a1eea935b892944b 100644 (file)
@@ -279,17 +279,11 @@ pkg_hash_check_unresolved(pkg_t *maybe)
 {
        char **unresolved = NULL;
        char **tmp;
-       pkg_vec_t *depends, *all;
-       int i, res = 0;
+       pkg_vec_t *depends;
+       int res = 0;
 
        depends = pkg_vec_alloc();
-       all = pkg_vec_alloc();
-       pkg_hash_fetch_available(all);
-       /* backup dependencies_checked marks, they get destroyed by pkg_hash_fetch_unsatisfied_dependencies */
-       for (i = 0; i < all->len; i++)
-               all->pkgs[i]->parent->prev_dependencies_checked = all->pkgs[i]->parent->dependencies_checked;
-
-       pkg_hash_fetch_unsatisfied_dependencies(maybe, depends, &unresolved);
+       pkg_hash_fetch_unsatisfied_dependencies(maybe, depends, &unresolved, 1);
 
        if (unresolved) {
                res = 1;
@@ -300,12 +294,6 @@ pkg_hash_check_unresolved(pkg_t *maybe)
        }
        pkg_vec_free(depends);
 
-       /* restore dependencies_checked marks */
-       for (i = 0; i < all->len; i++)
-               all->pkgs[i]->parent->dependencies_checked = all->pkgs[i]->parent->prev_dependencies_checked;
-
-       pkg_vec_free(all);
-
        return res;
 }
 
@@ -411,13 +399,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))
-                                   &&
-                                   (!pkg_hash_check_unresolved(maybe))) {
-                                       max_count++;
-                                       abstract_pkg_vec_insert(matching_apkgs,
-                                                               maybe->parent);
-                                       pkg_vec_insert(matching_pkgs, maybe);
+                                   (!pkg_vec_contains(matching_pkgs, maybe))) {
+                                       if (!pkg_hash_check_unresolved(maybe)) {
+                                               max_count++;
+                                               abstract_pkg_vec_insert(matching_apkgs,
+                                                                       maybe->parent);
+                                               pkg_vec_insert(matching_pkgs, maybe);
+                                       }
                                }
                        }