xbps-remove: use xbps_binpkg_{arch,pkgver} for -O (clean-cache).

The new implementation is almost 1s faster than before on my system.
This commit is contained in:
Juan RP 2014-09-05 21:09:27 +02:00
parent d7d749312d
commit 1a024773af

View File

@ -41,32 +41,29 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
const char *key _unused, void *arg _unused, const char *key _unused, void *arg _unused,
bool *done _unused) bool *done _unused)
{ {
xbps_dictionary_t pkg_propsd, repo_pkgd; xbps_dictionary_t repo_pkgd;
const char *binpkg, *pkgver, *arch, *rsha256; const char *binpkg, *rsha256;
char *binpkgsig; char *binpkgsig, *pkgver, *arch;
int rv;
/* Internalize props.plist dictionary from binary pkg */ /* Internalize props.plist dictionary from binary pkg */
binpkg = xbps_string_cstring_nocopy(obj); binpkg = xbps_string_cstring_nocopy(obj);
pkg_propsd = xbps_get_pkg_plist_from_binpkg(binpkg, "./props.plist"); pkgver = xbps_binpkg_pkgver(binpkg);
if (pkg_propsd == NULL) { assert(pkgver);
rv = errno; arch = xbps_binpkg_arch(binpkg);
xbps_error_printf("Failed to read from %s: %s\n", binpkg, strerror(errno)); assert(arch);
return rv;
}
xbps_dictionary_get_cstring_nocopy(pkg_propsd, "architecture", &arch);
xbps_dictionary_get_cstring_nocopy(pkg_propsd, "pkgver", &pkgver);
if (!xbps_pkg_arch_match(xhp, arch, NULL)) { if (!xbps_pkg_arch_match(xhp, arch, NULL)) {
xbps_dbg_printf(xhp, "%s: ignoring pkg with unmatched arch (%s)\n", pkgver, arch); xbps_dbg_printf(xhp, "%s: ignoring pkg with unmatched arch (%s)\n", pkgver, arch);
xbps_object_release(pkg_propsd);
return 0; return 0;
} }
free(arch);
/* /*
* Remove binary pkg if it's not registered in any repository * Remove binary pkg if it's not registered in any repository
* or if hash doesn't match. * or if hash doesn't match.
*/ */
binpkgsig = xbps_xasprintf("%s.sig", binpkg); binpkgsig = xbps_xasprintf("%s.sig", binpkg);
repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver); repo_pkgd = xbps_rpool_get_pkg(xhp, pkgver);
free(pkgver);
if (repo_pkgd) { if (repo_pkgd) {
xbps_dictionary_get_cstring_nocopy(repo_pkgd, xbps_dictionary_get_cstring_nocopy(repo_pkgd,
"filename-sha256", &rsha256); "filename-sha256", &rsha256);
@ -82,7 +79,6 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
"`%s': %s\n", binpkgsig, strerror(errno)); "`%s': %s\n", binpkgsig, strerror(errno));
} }
} }
xbps_object_release(pkg_propsd);
free(binpkgsig); free(binpkgsig);
return 0; return 0;
} }
@ -96,7 +92,6 @@ cleaner_cb(struct xbps_handle *xhp, xbps_object_t obj,
fprintf(stderr, "Failed to remove `%s': %s\n", fprintf(stderr, "Failed to remove `%s': %s\n",
binpkgsig, strerror(errno)); binpkgsig, strerror(errno));
} }
xbps_object_release(pkg_propsd);
free(binpkgsig); free(binpkgsig);
return 0; return 0;
@ -117,6 +112,7 @@ clean_cachedir(struct xbps_handle *xhp)
if ((dirp = opendir(xhp->cachedir)) == NULL) if ((dirp = opendir(xhp->cachedir)) == NULL)
return 0; return 0;
array = xbps_array_create();
while ((dp = readdir(dirp)) != NULL) { while ((dp = readdir(dirp)) != NULL) {
if ((strcmp(dp->d_name, ".") == 0) || if ((strcmp(dp->d_name, ".") == 0) ||
(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); xbps_dbg_printf(xhp, "ignoring unknown file: %s\n", dp->d_name);
continue; continue;
} }
if (array == NULL)
array = xbps_array_create();
xbps_array_add_cstring(array, dp->d_name); xbps_array_add_cstring(array, dp->d_name);
} }
(void)closedir(dirp); (void)closedir(dirp);