From 1a024773afce64ff3a9d8d8b0dc550bb8cb9a585 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 5 Sep 2014 21:09:27 +0200 Subject: [PATCH] xbps-remove: use xbps_binpkg_{arch,pkgver} for -O (clean-cache). The new implementation is almost 1s faster than before on my system. --- bin/xbps-remove/clean-cache.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/bin/xbps-remove/clean-cache.c b/bin/xbps-remove/clean-cache.c index cacc6aa8..69ab0bda 100644 --- a/bin/xbps-remove/clean-cache.c +++ b/bin/xbps-remove/clean-cache.c @@ -41,32 +41,29 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, const char *key _unused, void *arg _unused, bool *done _unused) { - xbps_dictionary_t pkg_propsd, repo_pkgd; - const char *binpkg, *pkgver, *arch, *rsha256; - char *binpkgsig; - int rv; + xbps_dictionary_t repo_pkgd; + const char *binpkg, *rsha256; + char *binpkgsig, *pkgver, *arch; /* Internalize props.plist dictionary from binary pkg */ binpkg = xbps_string_cstring_nocopy(obj); - pkg_propsd = xbps_get_pkg_plist_from_binpkg(binpkg, "./props.plist"); - if (pkg_propsd == NULL) { - rv = errno; - xbps_error_printf("Failed to read from %s: %s\n", binpkg, strerror(errno)); - return rv; - } - xbps_dictionary_get_cstring_nocopy(pkg_propsd, "architecture", &arch); - xbps_dictionary_get_cstring_nocopy(pkg_propsd, "pkgver", &pkgver); + pkgver = xbps_binpkg_pkgver(binpkg); + assert(pkgver); + arch = xbps_binpkg_arch(binpkg); + assert(arch); + if (!xbps_pkg_arch_match(xhp, arch, NULL)) { xbps_dbg_printf(xhp, "%s: ignoring pkg with unmatched arch (%s)\n", pkgver, arch); - xbps_object_release(pkg_propsd); return 0; } + free(arch); /* * Remove binary pkg if it's not registered in any repository * or if hash doesn't match. */ binpkgsig = xbps_xasprintf("%s.sig", binpkg); repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver); + free(pkgver); if (repo_pkgd) { xbps_dictionary_get_cstring_nocopy(repo_pkgd, "filename-sha256", &rsha256); @@ -82,7 +79,6 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, "`%s': %s\n", binpkgsig, strerror(errno)); } } - xbps_object_release(pkg_propsd); free(binpkgsig); return 0; } @@ -96,7 +92,6 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj, fprintf(stderr, "Failed to remove `%s': %s\n", binpkgsig, strerror(errno)); } - xbps_object_release(pkg_propsd); free(binpkgsig); return 0; @@ -117,6 +112,7 @@ clean_cachedir(struct xbps_handle *xhp) if ((dirp = opendir(xhp->cachedir)) == NULL) return 0; + array = xbps_array_create(); while ((dp = readdir(dirp)) != NULL) { if ((strcmp(dp->d_name, ".") == 0) || (strcmp(dp->d_name, "..") == 0)) @@ -129,9 +125,6 @@ clean_cachedir(struct xbps_handle *xhp) xbps_dbg_printf(xhp, "ignoring unknown file: %s\n", dp->d_name); continue; } - if (array == NULL) - array = xbps_array_create(); - xbps_array_add_cstring(array, dp->d_name); } (void)closedir(dirp);