xbps-rindex: use xbps_binpkg_{arch,pkgver} for -r (remove-obsoletes).

This is magnituds faster than before; some results:

$ for f in 1 2 3; do time xbps-rindex -r /var/cache/xbps/ &>/dev/null; done

real 0m0.624s
user 0m2.163s
sys 0m0.032s

real 0m0.590s
user 0m2.159s
sys 0m0.023s

real 0m0.584s
user 0m2.144s
sys 0m0.039s

$ for f in 1 2 3; do time LD_PRELOAD=$PWD/lib/libxbps.so.2.0.0 ./bin/xbps-rindex/xbps-rindex -r /var/cache/xbps &>/dev/null; done

real 0m0.037s
user 0m0.030s
sys 0m0.010s

real 0m0.036s
user 0m0.032s
sys 0m0.007s

real 0m0.037s
user 0m0.035s
sys 0m0.006s
$
This commit is contained in:
Juan RP 2014-09-05 21:07:07 +02:00
parent b73d40092c
commit d7d749312d

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2012-2013 Juan Romero Pardines.
* Copyright (c) 2012-2014 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -67,43 +67,43 @@ remove_pkg(const char *repodir, const char *file)
static int
cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused, void *arg, bool *done _unused)
{
xbps_dictionary_t pkgd;
struct xbps_repo *repo = arg;
const char *binpkg, *pkgver, *arch;
const char *binpkg;
char *pkgver, *arch;
int rv;
binpkg = xbps_string_cstring_nocopy(obj);
pkgd = xbps_get_pkg_plist_from_binpkg(binpkg, "./props.plist");
if (pkgd == NULL) {
rv = remove_pkg(repo->uri, binpkg);
if (rv != 0) {
xbps_object_release(pkgd);
return 0;
if (access(binpkg, R_OK) == -1) {
if (errno == ENOENT) {
if ((rv = remove_pkg(repo->uri, binpkg)) != 0)
return 0;
printf("Removed broken package `%s'.\n", binpkg);
}
printf("Removed broken package `%s'.\n", binpkg);
}
xbps_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
xbps_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch);
arch = xbps_binpkg_arch(binpkg);
assert(arch);
/* ignore pkgs from other archs */
if (!xbps_pkg_arch_match(xhp, arch, NULL)) {
xbps_object_release(pkgd);
free(arch);
return 0;
}
pkgver = xbps_binpkg_pkgver(binpkg);
assert(pkgver);
if (xhp->flags & XBPS_FLAG_VERBOSE)
printf("checking %s (%s)\n", pkgver, binpkg);
/*
* If binpkg is not registered in index, remove binpkg.
*/
if (!xbps_repo_get_pkg(repo, pkgver)) {
rv = remove_pkg(repo->uri, binpkg);
if (rv != 0) {
xbps_object_release(pkgd);
if ((rv = remove_pkg(repo->uri, binpkg)) != 0) {
free(pkgver);
return 0;
}
printf("Removed obsolete package `%s'.\n", binpkg);
}
xbps_object_release(pkgd);
free(pkgver);
return 0;
}