static void process_array(const char *key, const char *val) { xbps_array_t array = NULL; char *args, *p = NULL, *saveptr = NULL; assert(key); if (val == NULL) return; array = xbps_array_create(); assert(array); if (strchr(val, ' ') == NULL) { xbps_array_add_cstring_nocopy(array, val); goto out; } args = strdup(val); assert(args); for ((p = strtok_r(args, " ", &saveptr)); p; (p = strtok_r(NULL, " ", &saveptr))) { xbps_array_add_cstring(array, p); } free(args); out: xbps_dictionary_set(pkg_propsd, key, array); xbps_object_release(array); }
ATF_TC_BODY(find_pkg_orphans_test, tc) { struct xbps_handle xh; xbps_array_t a, res; xbps_dictionary_t pkgd; xbps_string_t pstr; const char *pkgver, *tcsdir; unsigned int i; /* get test source dir */ tcsdir = atf_tc_get_config_var(tc, "srcdir"); memset(&xh, 0, sizeof(xh)); xbps_strlcpy(xh.rootdir, tcsdir, sizeof(xh.rootdir)); xbps_strlcpy(xh.metadir, tcsdir, sizeof(xh.metadir)); ATF_REQUIRE_EQ(xbps_init(&xh), 0); a = xbps_array_create(); xbps_array_add_cstring_nocopy(a, "xbps-git"); pstr = xbps_string_create(); res = xbps_find_pkg_orphans(&xh, a); for (i = 0; i < xbps_array_count(res); i++) { pkgd = xbps_array_get(res, i); xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); xbps_string_append_cstring(pstr, pkgver); xbps_string_append_cstring(pstr, "\n"); } ATF_REQUIRE_STREQ(xbps_string_cstring_nocopy(pstr), expected_output); }
static void generate_full_revdeps_tree(struct xbps_handle *xhp) { xbps_object_t obj; xbps_object_iterator_t iter; if (xhp->pkgdb_revdeps) return; xhp->pkgdb_revdeps = xbps_dictionary_create(); assert(xhp->pkgdb_revdeps); iter = xbps_dictionary_iterator(xhp->pkgdb); assert(iter); while ((obj = xbps_object_iterator_next(iter))) { xbps_array_t rundeps; xbps_dictionary_t pkgd; const char *pkgver; pkgd = xbps_dictionary_get_keysym(xhp->pkgdb, obj); rundeps = xbps_dictionary_get(pkgd, "run_depends"); if (!xbps_array_count(rundeps)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); for (unsigned int i = 0; i < xbps_array_count(rundeps); i++) { xbps_array_t pkg; const char *pkgdep, *vpkgname; char *curpkgname; bool alloc = false; xbps_array_get_cstring_nocopy(rundeps, i, &pkgdep); curpkgname = xbps_pkgpattern_name(pkgdep); if (curpkgname == NULL) curpkgname = xbps_pkg_name(pkgdep); assert(curpkgname); vpkgname = vpkg_user_conf(xhp, curpkgname); if (vpkgname == NULL) vpkgname = curpkgname; pkg = xbps_dictionary_get(xhp->pkgdb_revdeps, vpkgname); if (pkg == NULL) { alloc = true; pkg = xbps_array_create(); } if (!xbps_match_string_in_array(pkg, pkgver)) { xbps_array_add_cstring_nocopy(pkg, pkgver); xbps_dictionary_set(xhp->pkgdb_revdeps, vpkgname, pkg); } free(curpkgname); if (alloc) xbps_object_release(pkg); } } xbps_object_iterator_release(iter); }
static void shlib_register(xbps_dictionary_t d, const char *shlib, const char *pkgver) { xbps_array_t array; bool alloc = false; if ((array = xbps_dictionary_get(d, shlib)) == NULL) { alloc = true; array = xbps_array_create(); xbps_dictionary_set(d, shlib, array); } if (!xbps_match_string_in_array(array, pkgver)) xbps_array_add_cstring_nocopy(array, pkgver); if (alloc) xbps_object_release(array); }
static xbps_array_t revdeps_match(struct xbps_repo *repo, xbps_dictionary_t tpkgd, const char *str) { xbps_dictionary_t pkgd; xbps_array_t revdeps = NULL, pkgdeps, provides; xbps_object_iterator_t iter; xbps_object_t obj; const char *pkgver, *tpkgver, *arch, *vpkg; iter = xbps_dictionary_iterator(repo->idx); assert(iter); while ((obj = xbps_object_iterator_next(iter))) { pkgd = xbps_dictionary_get_keysym(repo->idx, obj); if (xbps_dictionary_equals(pkgd, tpkgd)) continue; pkgdeps = xbps_dictionary_get(pkgd, "run_depends"); if (!xbps_array_count(pkgdeps)) continue; /* * Try to match passed in string. */ if (str) { if (!xbps_match_pkgdep_in_array(pkgdeps, str)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch); if (!xbps_pkg_arch_match(repo->xhp, arch, NULL)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &tpkgver); /* match */ if (revdeps == NULL) revdeps = xbps_array_create(); if (!xbps_match_string_in_array(revdeps, tpkgver)) xbps_array_add_cstring_nocopy(revdeps, tpkgver); continue; } /* * Try to match any virtual package. */ provides = xbps_dictionary_get(tpkgd, "provides"); for (unsigned int i = 0; i < xbps_array_count(provides); i++) { xbps_array_get_cstring_nocopy(provides, i, &vpkg); if (!xbps_match_pkgdep_in_array(pkgdeps, vpkg)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch); if (!xbps_pkg_arch_match(repo->xhp, arch, NULL)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &tpkgver); /* match */ if (revdeps == NULL) revdeps = xbps_array_create(); if (!xbps_match_string_in_array(revdeps, tpkgver)) xbps_array_add_cstring_nocopy(revdeps, tpkgver); } /* * Try to match by pkgver. */ xbps_dictionary_get_cstring_nocopy(tpkgd, "pkgver", &pkgver); if (!xbps_match_pkgdep_in_array(pkgdeps, pkgver)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch); if (!xbps_pkg_arch_match(repo->xhp, arch, NULL)) continue; xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &tpkgver); /* match */ if (revdeps == NULL) revdeps = xbps_array_create(); if (!xbps_match_string_in_array(revdeps, tpkgver)) xbps_array_add_cstring_nocopy(revdeps, tpkgver); } xbps_object_iterator_release(iter); return revdeps; }