libopkg: consider provided packages in pkg_vec_mark_if_matches()
[project/opkg-lede.git] / libopkg / pkg_vec.c
index 162c70ff9f0597443f83e4c0b27251cf9a740ba5..a9e2e73f8b96700ea35988a986d470258904ef49 100644 (file)
@@ -52,27 +52,29 @@ void pkg_vec_insert_merge(pkg_vec_t * vec, pkg_t * pkg, int set_status)
 {
        int i;
        int found = 0;
+       char *pkg_version = pkg_get_string(pkg, PKG_VERSION);
+       char *pkg_architecture = pkg_get_architecture(pkg);
+       char *vec_architecture;
 
        /* look for a duplicate pkg by name, version, and architecture */
        for (i = 0; i < vec->len; i++) {
+               vec_architecture = pkg_get_architecture(vec->pkgs[i]);
+
                opkg_msg(DEBUG2, "%s %s arch=%s vs. %s %s arch=%s.\n",
-                        pkg->name, pkg->version, pkg->architecture,
-                        vec->pkgs[i]->name, vec->pkgs[i]->version,
-                        vec->pkgs[i]->architecture);
+                        pkg->name, pkg_version, pkg_architecture,
+                        vec->pkgs[i]->name, pkg_get_string(vec->pkgs[i], PKG_VERSION),
+                        vec_architecture);
                /* if the name,ver,arch matches, or the name matches and the
                 * package is marked deinstall/hold  */
                if ((!strcmp(pkg->name, vec->pkgs[i]->name))
                    && ((pkg->state_want == SW_DEINSTALL
                         && (pkg->state_flag & SF_HOLD))
                        || ((pkg_compare_versions(pkg, vec->pkgs[i]) == 0)
-                           &&
-                           (!strcmp
-                            (pkg->architecture,
-                             vec->pkgs[i]->architecture))))) {
+                           && (!strcmp(pkg_architecture, vec_architecture))))) {
                        found = 1;
                        opkg_msg(DEBUG2,
                                 "Duplicate for pkg=%s version=%s arch=%s.\n",
-                                pkg->name, pkg->version, pkg->architecture);
+                                pkg->name, pkg_version, pkg_architecture);
                        break;
                }
        }
@@ -80,14 +82,14 @@ void pkg_vec_insert_merge(pkg_vec_t * vec, pkg_t * pkg, int set_status)
        /* we didn't find one, add it */
        if (!found) {
                opkg_msg(DEBUG2, "Adding new pkg=%s version=%s arch=%s.\n",
-                        pkg->name, pkg->version, pkg->architecture);
+                        pkg->name, pkg_version, pkg_architecture);
                pkg_vec_insert(vec, pkg);
                return;
        }
 
        /* update the one that we have */
        opkg_msg(DEBUG2, "Merging %s %s arch=%s, set_status=%d.\n",
-                pkg->name, pkg->version, pkg->architecture, set_status);
+                pkg->name, pkg_version, pkg_architecture, set_status);
        if (set_status) {
                /* This is from the status file,
                 * so need to merge with existing database */
@@ -138,12 +140,24 @@ int pkg_vec_mark_if_matches(pkg_vec_t * vec, const char *pattern)
        pkg_t **pkgs = vec->pkgs;
        int npkgs = vec->len;
        int i;
+       abstract_pkg_t **providers, *provider;
+
        for (i = 0; i < npkgs; i++) {
                pkg_t *pkg = pkgs[i];
                if (fnmatch(pattern, pkg->name, 0) == 0) {
                        pkg->state_flag |= SF_MARKED;
                        matching_count++;
                }
+               else {
+                       providers = pkg_get_ptr(pkg, PKG_PROVIDES);
+                       while (providers && *providers) {
+                               provider = *providers++;
+                               if (fnmatch(pattern, provider->name, 0) == 0) {
+                                       pkg->state_flag |= SF_MARKED;
+                                       matching_count++;
+                               }
+                       }
+               }
        }
        return matching_count;
 }
@@ -194,7 +208,7 @@ int abstract_pkg_vec_contains(abstract_pkg_vec_t * vec, abstract_pkg_t * apkg)
        return 0;
 }
 
-void abstract_pkg_vec_sort(pkg_vec_t * vec, compare_fcn_t compar)
+void abstract_pkg_vec_sort(abstract_pkg_vec_t * vec, compare_fcn_t compar)
 {
        qsort(vec->pkgs, vec->len, sizeof(pkg_t *), compar);
 }