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

@@ -510,7 +510,7 @@ main(int argc, char **argv)
/*
* Internalize the plist file of the target installed package.
*/
plistd = xbps_pkgd_from_metadir(&xh, argv[0]);
plistd = xbps_metadir_get_pkgd(&xh, argv[0]);
if (plistd == NULL)
die("cannot internalize %s metadata file", argv[0]);
@@ -525,7 +525,6 @@ main(int argc, char **argv)
*/
create_dot_graph(&xh, f, plistd, confd, revdeps);
prop_object_release(plistd);
prop_object_release(confd);
xbps_end(&xh);

View File

@@ -122,7 +122,7 @@ check_pkg_integrity(struct xbps_handle *xhp,
/*
* Check for props.plist metadata file.
*/
propsd = xbps_pkgd_from_metadir(xhp, pkgname);
propsd = xbps_metadir_get_pkgd(xhp, pkgname);
if (propsd == NULL) {
printf("%s: unexistent metafile, converting to 0.18 "
"format...\n", pkgname);
@@ -183,8 +183,6 @@ out1:
#undef RUN_PKG_CHECK
out:
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
prop_object_release(propsd);
if (broken)
return 1;

View File

@@ -29,7 +29,7 @@
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/param.h>
#include <assert.h>
#include <xbps_api.h>
#include "defs.h"
@@ -65,7 +65,7 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
* Internalize current pkg props dictionary from its
* installed metadata directory.
*/
curpkg_propsd = xbps_pkgd_from_metadir(xhp, curpkgn);
curpkg_propsd = xbps_metadir_get_pkgd(xhp, curpkgn);
if (curpkg_propsd == NULL) {
xbps_error_printf("%s: missing %s metadata file!\n",
curpkgn, XBPS_PKGPROPS);
@@ -75,7 +75,6 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
prop_dictionary_get(curpkg_propsd, "run_depends");
if (curpkg_rdeps == NULL) {
/* package has no rundeps, skip */
prop_object_release(curpkg_propsd);
return 0;
}
/*
@@ -90,13 +89,11 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
provides = prop_dictionary_get(obj, "provides");
if (provides == NULL) {
/* doesn't provide any virtual pkg */
prop_object_release(curpkg_propsd);
return 0;
}
if (!xbps_match_any_virtualpkg_in_rundeps(curpkg_rdeps,
provides)) {
/* doesn't match any virtual pkg */
prop_object_release(curpkg_propsd);
return 0;
}
}
@@ -113,7 +110,6 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
* Current package already requires our package,
* this is good so skip it.
*/
prop_object_release(curpkg_propsd);
return 0;
}
} else {
@@ -121,22 +117,18 @@ check_reqby_pkg_cb(struct xbps_handle *xhp,
* Missing requiredby array object, create it.
*/
crd->pkgd_reqby = prop_array_create();
if (crd->pkgd_reqby == NULL) {
prop_object_release(curpkg_propsd);
return -1;
}
assert(crd->pkgd_reqby);
crd->pkgd_reqby_alloc = true;
}
/*
* Added pkgdep into pkg's requiredby array.
*/
if (!prop_array_add(crd->pkgd_reqby, curpkgver)) {
prop_object_release(curpkg_propsd);
if (!prop_array_add(crd->pkgd_reqby, curpkgver))
return -1;
}
printf("%s: added missing requiredby entry for %s.\n\n",
crd->pkgver, prop_string_cstring_nocopy(curpkgver));
prop_object_release(curpkg_propsd);
return 1;
}
@@ -170,7 +162,6 @@ remove_stale_entries_in_reqby(struct xbps_handle *xhp,
}
if (needs_update) {
prop_dictionary_set(crd->pkgd, "requiredby", crd->pkgd_reqby);
printf("%s: requiredby fix done!\n\n", crd->pkgver);
return true;
}
return false;

View File

@@ -95,7 +95,7 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp, prop_object_t obj, void *arg, bool *do
(void)done;
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
pkgmetad = xbps_metadir_get_pkgd(xhp, pkgname);
files_keys = prop_dictionary_all_keys(pkgmetad);
for (i = 0; i < prop_array_count(files_keys); i++) {
@@ -106,7 +106,6 @@ ownedby_pkgdb_cb(struct xbps_handle *xhp, prop_object_t obj, void *arg, bool *do
break;
}
prop_object_release(files_keys);
prop_object_release(pkgmetad);
return rv;
}

View File

@@ -44,13 +44,12 @@ show_pkg_deps(struct xbps_handle *xhp, const char *pkgname)
/*
* Check for props.plist metadata file.
*/
propsd = xbps_pkgd_from_metadir(xhp, pkgname);
propsd = xbps_metadir_get_pkgd(xhp, pkgname);
if (propsd == NULL)
return ENOENT;
rv = xbps_callback_array_iter_in_dict(xhp, propsd, "run_depends",
list_strings_sep_in_array, NULL);
prop_object_release(propsd);
return rv;
}

View File

@@ -220,16 +220,15 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
const char *instdate, *pname;
bool autoinst;
d = xbps_pkgd_from_metadir(xhp, pkgname);
d = xbps_metadir_get_pkgd(xhp, pkgname);
if (d == NULL)
return ENOENT;
prop_dictionary_get_cstring_nocopy(d, "pkgname", &pname);
pkgdb_d = xbps_pkgdb_get_pkgd(xhp, pname, false);
if (pkgdb_d == NULL) {
prop_object_release(d);
if (pkgdb_d == NULL)
return EINVAL;
}
if (prop_dictionary_get_cstring_nocopy(pkgdb_d,
"install-date", &instdate))
prop_dictionary_set_cstring_nocopy(d, "install-date",
@@ -243,7 +242,6 @@ show_pkg_info_from_metadir(struct xbps_handle *xhp,
else
show_pkg_info_one(d, option);
prop_object_release(d);
return 0;
}
@@ -253,12 +251,11 @@ show_pkg_files_from_metadir(struct xbps_handle *xhp, const char *pkgname)
prop_dictionary_t d;
int rv = 0;
d = xbps_pkgd_from_metadir(xhp, pkgname);
d = xbps_metadir_get_pkgd(xhp, pkgname);
if (d == NULL)
return ENOENT;
rv = show_pkg_files(d);
prop_object_release(d);
return rv;
}

View File

@@ -43,7 +43,7 @@ write_plist_file(prop_dictionary_t dict, const char *file)
if (!prop_dictionary_externalize_to_zfile(dict, file)) {
prop_object_release(dict);
xbps_error_printf("xbps-uhelper: couldn't write to %s: %s",
xbps_error_printf("xbps-uhelper: couldn't write to %s: %s\n",
file, strerror(errno));
exit(EXIT_FAILURE);
}