diff --git a/NEWS b/NEWS index 21c7b3b2..d5366ebd 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,9 @@ xbps-0.44 (???): + * 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. + * xbps-query(8): only compile the ERE (Extended Regular Expression) once in the ownedby mode. A performance improvement suggested by Christian Neukirchen. diff --git a/lib/package_orphans.c b/lib/package_orphans.c index a6847c85..f1419242 100644 --- a/lib/package_orphans.c +++ b/lib/package_orphans.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2009-2014 Juan Romero Pardines. + * Copyright (c) 2009-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -68,7 +68,7 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user _unused xbps_object_iterator_t iter; const char *curpkgver, *deppkgver, *reqbydep; bool automatic = false; - unsigned int cnt, reqbycnt; + unsigned int i, cnt, reqbycnt; if (xbps_pkgdb_init(xhp) != 0) return NULL; @@ -78,16 +78,13 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user _unused /* * Add all packages specified by the client. */ - for (unsigned int i = 0; i < xbps_array_count(orphans_user); i++) { + for (i = 0; i < xbps_array_count(orphans_user); i++) { xbps_array_get_cstring_nocopy(orphans_user, i, &curpkgver); pkgd = xbps_pkgdb_get_pkg(xhp, curpkgver); if (pkgd == NULL) continue; xbps_array_add(array, pkgd); } - if (xbps_array_count(array)) - goto find_orphans; - iter = xbps_dictionary_iterator(xhp->pkgdb); assert(iter); /* @@ -116,15 +113,19 @@ xbps_find_pkg_orphans(struct xbps_handle *xhp, xbps_array_t orphans_user _unused } xbps_object_iterator_release(iter); -find_orphans: - for (unsigned int i = 0; i < xbps_array_count(array); i++) { + for (i = 0; i < xbps_array_count(array); i++) { pkgd = xbps_array_get(array, i); - rdeps = xbps_dictionary_get(pkgd, "run_depends"); + xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &curpkgver); + rdeps = xbps_pkgdb_get_pkg_fulldeptree(xhp, curpkgver); for (unsigned int x = 0; x < xbps_array_count(rdeps); x++) { cnt = 0; xbps_array_get_cstring_nocopy(rdeps, x, &deppkgver); - if (xbps_find_pkg_in_array(array, deppkgver, NULL) || - xbps_find_virtualpkg_in_array(xhp, array, deppkgver, NULL)) + if (xbps_find_pkg_in_array(array, deppkgver, NULL)) + continue; + deppkgd = xbps_pkgdb_get_pkg(xhp, deppkgver); + automatic = false; + xbps_dictionary_get_bool(deppkgd, "automatic-install", &automatic); + if (!automatic) continue; reqby = xbps_pkgdb_get_pkg_revdeps(xhp, deppkgver); if (reqby == NULL) @@ -132,17 +133,11 @@ find_orphans: reqbycnt = xbps_array_count(reqby); for (unsigned int j = 0; j < reqbycnt; j++) { xbps_array_get_cstring_nocopy(reqby, j, &reqbydep); - if (xbps_find_pkg_in_array(array, reqbydep, NULL) || - xbps_find_virtualpkg_in_array(xhp, array, reqbydep, NULL)) + if (xbps_find_pkg_in_array(array, reqbydep, NULL)) cnt++; } - if (cnt == reqbycnt) { - deppkgd = xbps_pkgdb_get_pkg(xhp, deppkgver); - automatic = false; - xbps_dictionary_get_bool(deppkgd, "automatic-install", &automatic); - if (automatic) - xbps_array_add(array, deppkgd); - } + if (cnt == reqbycnt) + xbps_array_add(array, deppkgd); } } diff --git a/lib/pkgdb.c b/lib/pkgdb.c index 81b2460c..d3f6f708 100644 --- a/lib/pkgdb.c +++ b/lib/pkgdb.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 @@ -324,15 +324,17 @@ generate_full_revdeps_tree(struct xbps_handle *xhp) 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, *pkgver, *vpkgname; + const char *pkgdep, *vpkgname; char *curpkgname; bool alloc = false; @@ -350,7 +352,6 @@ generate_full_revdeps_tree(struct xbps_handle *xhp) alloc = true; pkg = xbps_array_create(); } - xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver); if (!xbps_match_string_in_array(pkg, pkgver)) { xbps_array_add_cstring_nocopy(pkg, pkgver); xbps_dictionary_set(xhp->pkgdb_revdeps, vpkgname, pkg); diff --git a/tests/xbps/libxbps/find_pkg_orphans/main.c b/tests/xbps/libxbps/find_pkg_orphans/main.c index df8869fe..eec72f20 100644 --- a/tests/xbps/libxbps/find_pkg_orphans/main.c +++ b/tests/xbps/libxbps/find_pkg_orphans/main.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2013 Juan Romero Pardines. + * Copyright (c) 2013-2015 Juan Romero Pardines. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -28,20 +28,27 @@ static const char expected_output[] = "xbps-git-20130310_2\n" + "unexistent-pkg-0_1\n" + "xbps-triggers-1.0_1\n" "libxbps-git-20130310_2\n" + "orphan1-0_1\n" + "orphan0-0_1\n" + "confuse-2.7_2\n" "proplib-0.6.3_1\n" "libarchive-3.1.2_1\n" "libfetch-2.34_1\n" - "confuse-2.7_2\n" + "bzip2-1.0.5_1\n" + "liblzma-5.0.4_3\n" + "expat-2.1.0_3\n" + "attr-2.4.46_5\n" "libssl-1.0.1e_3\n" "zlib-1.2.7_1\n" - "attr-2.4.46_5\n" - "expat-2.1.0_3\n" - "liblzma-5.0.4_3\n"; + "glibc-2.20_1\n"; static const char expected_output_all[] = - "orphan0-0_1\n" - "unexistent-pkg-0_1\n"; + "unexistent-pkg-0_1\n" + "orphan1-0_1\n" + "orphan0-0_1\n"; ATF_TC(find_pkg_orphans_test); ATF_TC_HEAD(find_pkg_orphans_test, tc) diff --git a/tests/xbps/libxbps/find_pkg_orphans/pkgdb-0.38.plist b/tests/xbps/libxbps/find_pkg_orphans/pkgdb-0.38.plist index 629daf4b..a9064cb5 100644 --- a/tests/xbps/libxbps/find_pkg_orphans/pkgdb-0.38.plist +++ b/tests/xbps/libxbps/find_pkg_orphans/pkgdb-0.38.plist @@ -2,6 +2,24 @@ + xbps-triggers + + automatic-install + + pkgver + xbps-triggers-1.0_1 + state + installed + + glibc + + automatic-install + + pkgver + glibc-2.20_1 + state + installed + attr automatic-install @@ -28,6 +46,19 @@ state installed + bzip2 + + automatic-install + + pkgver + bzip2-1.0.5_1 + run_depends + + glibc>=2.8_1 + + state + installed + expat automatic-install @@ -144,6 +175,11 @@ pkgver unexistent-pkg-0_1 + run_depends + + orphan0-0_1 + orphan1-0_1 + state installed @@ -153,10 +189,15 @@ pkgver orphan0-0_1 - run_depends - - unexistent-pkg>=0 - + state + installed + + orphan1 + + automatic-install + + pkgver + orphan1-0_1 state installed @@ -177,6 +218,7 @@ glibc>=2.8_1 proplib>=0.1_1 libarchive>=3.1.2_1 + zlib>=1.2_1 state installed