diff --git a/NEWS b/NEWS index d5366ebd..03a3b376 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.44 (???): + * libxbps: the provides obj (array of strings) now fully expects exact + pkgver strings, such as `foo-1.0_1`. Incomplete components such as + `pkgname` or `pkgname-9` are not accepted anymore. + * libxbps: detection of orphaned pkgs is now 66% faster (and even more in some cases). This improves the performance of `xbps-remove -R` (recursively remove a pkg and its dependencies) and `xbps-remove -o` (remove orphaned pkgs) marginally. diff --git a/lib/plist_match.c b/lib/plist_match.c index 97413781..6dac70e2 100644 --- a/lib/plist_match.c +++ b/lib/plist_match.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2008-2014 Juan Romero Pardines. + * Copyright (c) 2008-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -70,34 +70,23 @@ xbps_match_any_virtualpkg_in_rundeps(xbps_array_t rundeps, xbps_object_t obj, obj2; xbps_object_iterator_t iter, iter2; const char *vpkgver, *pkgpattern; - char *tmp; iter = xbps_array_iterator(provides); assert(iter); while ((obj = xbps_object_iterator_next(iter))) { - tmp = NULL; vpkgver = xbps_string_cstring_nocopy(obj); - if (strchr(vpkgver, '_') == NULL) { - tmp = xbps_xasprintf("%s_1", vpkgver); - vpkgver = tmp; - } iter2 = xbps_array_iterator(rundeps); assert(iter2); while ((obj2 = xbps_object_iterator_next(iter2))) { pkgpattern = xbps_string_cstring_nocopy(obj2); if (xbps_pkgpattern_match(vpkgver, pkgpattern)) { - if (tmp != NULL) - free(tmp); - xbps_object_iterator_release(iter2); xbps_object_iterator_release(iter); return true; } } xbps_object_iterator_release(iter2); - if (tmp != NULL) - free(tmp); } xbps_object_iterator_release(iter); @@ -110,7 +99,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) xbps_object_iterator_t iter; xbps_object_t obj; const char *pkgdep; - char *curpkgname, *tmp; + char *curpkgname; bool found = false; assert(xbps_object_type(array) == XBPS_TYPE_ARRAY); @@ -120,7 +109,6 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) assert(iter); while ((obj = xbps_object_iterator_next(iter))) { - tmp = NULL; if (mode == 0) { /* match by string */ if (xbps_string_equals_cstring(obj, str)) { @@ -130,13 +118,7 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) } else if (mode == 1) { /* match by pkgname against pkgver */ pkgdep = xbps_string_cstring_nocopy(obj); - if (strchr(pkgdep, '_') == NULL) { - tmp = xbps_xasprintf("%s_1", pkgdep); - curpkgname = xbps_pkg_name(tmp); - free(tmp); - } else { - curpkgname = xbps_pkg_name(pkgdep); - } + curpkgname = xbps_pkg_name(pkgdep); if (curpkgname == NULL) break; if (strcmp(curpkgname, str) == 0) { @@ -160,34 +142,17 @@ match_string_in_array(xbps_array_t array, const char *str, int mode) } else if (mode == 3) { /* match pkgpattern against pkgdep */ pkgdep = xbps_string_cstring_nocopy(obj); - if (strchr(pkgdep, '_') == NULL) { - tmp = xbps_xasprintf("%s_1", pkgdep); - pkgdep = tmp; - } if (xbps_pkgpattern_match(pkgdep, str)) { - if (tmp != NULL) - free(tmp); found = true; break; } - if (tmp != NULL) - free(tmp); - } else if (mode == 4) { /* match pkgdep against pkgpattern */ pkgdep = xbps_string_cstring_nocopy(obj); - if (strchr(pkgdep, '_') == NULL) { - tmp = xbps_xasprintf("%s_1", pkgdep); - pkgdep = tmp; - } if (xbps_pkgpattern_match(str, pkgdep)) { - if (tmp != NULL) - free(tmp); found = true; break; } - if (tmp != NULL) - free(tmp); } } xbps_object_iterator_release(iter); diff --git a/lib/repo.c b/lib/repo.c index 67e556bf..6c7070ca 100644 --- a/lib/repo.c +++ b/lib/repo.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2014 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -333,7 +333,6 @@ revdeps_match(struct xbps_repo *repo, xbps_dictionary_t tpkgd, const char *str) xbps_object_iterator_t iter; xbps_object_t obj; const char *pkgver, *tpkgver, *arch, *vpkg; - char *buf; iter = xbps_dictionary_iterator(repo->idx); assert(iter); @@ -374,16 +373,9 @@ revdeps_match(struct xbps_repo *repo, xbps_dictionary_t tpkgd, const char *str) 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 (strchr(vpkg, '_') == NULL) - buf = xbps_xasprintf("%s_1", vpkg); - else - buf = strdup(vpkg); - - if (!xbps_match_pkgdep_in_array(pkgdeps, buf)) { - free(buf); + if (!xbps_match_pkgdep_in_array(pkgdeps, vpkg)) continue; - } - free(buf); + xbps_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch); if (!xbps_pkg_arch_match(repo->xhp, arch, NULL)) @@ -428,7 +420,6 @@ xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg) xbps_array_t revdeps = NULL, vdeps = NULL; xbps_dictionary_t pkgd; const char *vpkg; - char *buf = NULL; bool match = false; if (repo->idx == NULL) @@ -447,26 +438,18 @@ xbps_repo_get_pkg_revdeps(struct xbps_repo *repo, const char *pkg) char *vpkgn; xbps_array_get_cstring_nocopy(vdeps, i, &vpkg); - if (strchr(vpkg, '_') == NULL) - buf = xbps_xasprintf("%s_1", vpkg); - else - buf = strdup(vpkg); - - vpkgn = xbps_pkg_name(buf); + vpkgn = xbps_pkg_name(vpkg); assert(vpkgn); if (strcmp(vpkgn, pkg) == 0) { free(vpkgn); + match = true; break; } free(vpkgn); - free(buf); - buf = NULL; - } - if (buf) { - match = true; - revdeps = revdeps_match(repo, pkgd, buf); - free(buf); + vpkg = NULL; } + if (match) + revdeps = revdeps_match(repo, pkgd, vpkg); } if (!match) revdeps = revdeps_match(repo, pkgd, NULL); diff --git a/tests/xbps/libxbps/plist_match_virtual/main.c b/tests/xbps/libxbps/plist_match_virtual/main.c index 789209ac..d887c0ba 100644 --- a/tests/xbps/libxbps/plist_match_virtual/main.c +++ b/tests/xbps/libxbps/plist_match_virtual/main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2012-2014 Juan Romero Pardines. + * Copyright (c) 2012-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -48,8 +48,8 @@ provides_init(void) a = xbps_array_create(); ATF_REQUIRE(a != NULL); - xbps_array_add_cstring_nocopy(a, "cron-daemon-0"); - xbps_array_add_cstring_nocopy(a, "xbps-9999"); + xbps_array_add_cstring_nocopy(a, "cron-daemon-0_1"); + xbps_array_add_cstring_nocopy(a, "xbps-9999_1"); return a; }