From b232ca181537f8c55456924de07d07058bb49a5c Mon Sep 17 00:00:00 2001 From: Juan RP Date: Thu, 22 Dec 2011 12:56:56 +0100 Subject: [PATCH] libxbps: cache regpkgdb just when it's needed not via xbps_init(). --- lib/initend.c | 11 ----------- lib/package_configure.c | 5 +++++ lib/package_orphans.c | 5 +++++ lib/package_purge.c | 5 +++++ lib/plist_find.c | 11 +++++++++-- lib/transaction_ops.c | 8 +++++--- 6 files changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/initend.c b/lib/initend.c index f101dc2d..160d2965 100644 --- a/lib/initend.c +++ b/lib/initend.c @@ -177,17 +177,6 @@ xbps_init(struct xbps_handle *xh) xbps_dbg_printf("fetch-cacheconn=%u\n", cc); xbps_dbg_printf("fetch-cacheconn-host=%u\n", cch); xbps_dbg_printf("syslog=%u\n", xhp->syslog_enabled); - /* - * Initialize regpkgdb dictionary. - */ - if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { - if (rv != ENOENT) { - xbps_dbg_printf("%s: couldn't initialize " - "regpkgdb: %s\n", strerror(rv)); - xbps_end(xh); - return EINVAL; - } - } return 0; } diff --git a/lib/package_configure.c b/lib/package_configure.c index 57ad095b..3f004689 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -56,6 +56,11 @@ xbps_configure_packages(void) int rv = 0; xhp = xbps_handle_get(); + if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { + xbps_dbg_printf("%s: couldn't initialize " + "regpkgdb: %s\n", strerror(rv)); + return rv; + } iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages"); if (iter == NULL) return errno; diff --git a/lib/package_orphans.c b/lib/package_orphans.c index 7ee77ce1..0095fa55 100644 --- a/lib/package_orphans.c +++ b/lib/package_orphans.c @@ -182,6 +182,11 @@ xbps_find_pkg_orphans(prop_array_t orphans_user) * in which packages were installed. */ od.orphans_user = orphans_user; + if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { + xbps_dbg_printf("%s: couldn't initialize " + "regpkgdb: %s\n", strerror(rv)); + return NULL; + } rv = xbps_callback_array_iter_reverse_in_dict(xhp->regpkgdb_dictionary, "packages", find_orphan_pkg, &od); if (rv != 0) { diff --git a/lib/package_purge.c b/lib/package_purge.c index e4bd39a5..ef96ac1f 100644 --- a/lib/package_purge.c +++ b/lib/package_purge.c @@ -108,6 +108,11 @@ xbps_purge_packages(void) int rv = 0; xhp = xbps_handle_get(); + if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { + xbps_dbg_printf("%s: couldn't initialize " + "regpkgdb: %s\n", strerror(rv)); + return rv; + } iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages"); if (iter == NULL) return errno; diff --git a/lib/plist_find.c b/lib/plist_find.c index 744f8d8b..1e22e6e5 100644 --- a/lib/plist_find.c +++ b/lib/plist_find.c @@ -320,12 +320,19 @@ find_pkgd_installed(const char *str, bool bypattern, bool virtual) struct xbps_handle *xhp; prop_dictionary_t pkgd, rpkgd = NULL; pkg_state_t state = 0; + int rv; assert(str != NULL); xhp = xbps_handle_get(); - if (xhp->regpkgdb_dictionary == NULL) - return NULL; + if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { + if (rv != ENOENT) { + xbps_dbg_printf("%s: couldn't initialize " + "regpkgdb: %s\n", strerror(rv)); + return NULL; + } else if (rv == ENOENT) + return NULL; + } /* try normal pkg */ if (virtual == false) { diff --git a/lib/transaction_ops.c b/lib/transaction_ops.c index 81719f60..4cc6e2a9 100644 --- a/lib/transaction_ops.c +++ b/lib/transaction_ops.c @@ -188,9 +188,11 @@ xbps_transaction_update_packages(void) bool newpkg_found = false; xhp = xbps_handle_get(); - if (xhp->regpkgdb_dictionary == NULL) - return ENOENT; - + if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0) { + xbps_dbg_printf("%s: couldn't initialize " + "regpkgdb: %s\n", strerror(rv)); + return rv; + } iter = xbps_array_iter_from_dict(xhp->regpkgdb_dictionary, "packages"); if (iter == NULL) return ENOENT;