Implemented a cache to get pkg dicts from metadir.

This improves xbps-pkgdb -a marginally, but still seems to be a bit slow.
This commit is contained in:
Juan RP
2012-11-16 21:50:52 +01:00
parent 34bd49f85a
commit b0fab7a3ee
17 changed files with 139 additions and 88 deletions

View File

@ -264,40 +264,3 @@ xbps_array_replace_dict_by_pattern(prop_array_t array,
{
return array_replace_dict(array, dict, pattern, true);
}
prop_dictionary_t
xbps_pkgd_from_metadir(struct xbps_handle *xhp, const char *name)
{
prop_dictionary_t pkgd, plistd = NULL;
const char *savedpkgname;
char *plistf;
assert(name != NULL);
savedpkgname = name;
plistf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, name);
if (access(plistf, R_OK) == -1) {
pkgd = xbps_find_virtualpkg_dict_installed(xhp, name, false);
if (pkgd == NULL)
pkgd = xbps_find_pkg_dict_installed(xhp, name, false);
if (pkgd != NULL) {
free(plistf);
prop_dictionary_get_cstring_nocopy(pkgd,
"pkgname", &savedpkgname);
plistf = xbps_xasprintf("%s/.%s.plist",
xhp->metadir, savedpkgname);
}
}
plistd = prop_dictionary_internalize_from_zfile(plistf);
free(plistf);
if (plistd == NULL) {
xbps_dbg_printf(xhp, "cannot read from metadata %s for %s: %s\n",
plistf, savedpkgname, strerror(errno));
return NULL;
}
return plistd;
}