libxbps: detection of orphaned packages is now 66% faster.

This commit is contained in:
Juan RP 2015-01-10 05:43:35 +01:00
parent 0ec2dd98ce
commit 1f6a5c0e47
5 changed files with 83 additions and 34 deletions

4
NEWS
View File

@ -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.

View File

@ -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,19 +133,13 @@ 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)
if (cnt == reqbycnt)
xbps_array_add(array, deppkgd);
}
}
}
return array;
}

View File

@ -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);

View File

@ -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)

View File

@ -2,6 +2,24 @@
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>xbps-triggers</key>
<dict>
<key>automatic-install</key>
<true/>
<key>pkgver</key>
<string>xbps-triggers-1.0_1</string>
<key>state</key>
<string>installed</string>
</dict>
<key>glibc</key>
<dict>
<key>automatic-install</key>
<true/>
<key>pkgver</key>
<string>glibc-2.20_1</string>
<key>state</key>
<string>installed</string>
</dict>
<key>attr</key>
<dict>
<key>automatic-install</key>
@ -28,6 +46,19 @@
<key>state</key>
<string>installed</string>
</dict>
<key>bzip2</key>
<dict>
<key>automatic-install</key>
<true/>
<key>pkgver</key>
<string>bzip2-1.0.5_1</string>
<key>run_depends</key>
<array>
<string>glibc&gt;=2.8_1</string>
</array>
<key>state</key>
<string>installed</string>
</dict>
<key>expat</key>
<dict>
<key>automatic-install</key>
@ -144,6 +175,11 @@
<true/>
<key>pkgver</key>
<string>unexistent-pkg-0_1</string>
<key>run_depends</key>
<array>
<string>orphan0-0_1</string>
<string>orphan1-0_1</string>
</array>
<key>state</key>
<string>installed</string>
</dict>
@ -153,10 +189,15 @@
<true/>
<key>pkgver</key>
<string>orphan0-0_1</string>
<key>run_depends</key>
<array>
<string>unexistent-pkg&gt;=0</string>
</array>
<key>state</key>
<string>installed</string>
</dict>
<key>orphan1</key>
<dict>
<key>automatic-install</key>
<true/>
<key>pkgver</key>
<string>orphan1-0_1</string>
<key>state</key>
<string>installed</string>
</dict>
@ -177,6 +218,7 @@
<string>glibc&gt;=2.8_1</string>
<string>proplib&gt;=0.1_1</string>
<string>libarchive&gt;=3.1.2_1</string>
<string>zlib&gt;=1.2_1</string>
</array>
<key>state</key>
<string>installed</string>