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:
@ -44,7 +44,7 @@ EXTOBJS += external/mkpath.o
|
||||
OBJS = package_configure.o package_config_files.o package_orphans.o
|
||||
OBJS += package_remove.o package_remove_obsoletes.o package_state.o
|
||||
OBJS += package_unpack.o package_requiredby.o package_register.o
|
||||
OBJS += package_script.o
|
||||
OBJS += package_script.o package_metadir.o
|
||||
OBJS += transaction_commit.o transaction_package_replace.o
|
||||
OBJS += transaction_dictionary.o transaction_sortdeps.o transaction_ops.o
|
||||
OBJS += download.o initend.o pkgdb.o package_conflicts.o
|
||||
|
@ -232,6 +232,7 @@ xbps_end(struct xbps_handle *xhp)
|
||||
|
||||
xbps_pkgdb_release(xhp);
|
||||
xbps_rpool_release(xhp);
|
||||
xbps_metadir_release(xhp);
|
||||
xbps_fetch_unset_cache_connection();
|
||||
|
||||
cfg_free(xhp->cfg);
|
||||
|
@ -91,12 +91,11 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
xbps_dbg_printf(xhp, "%s-%s: processing conf_file %s\n",
|
||||
pkgname, version, entry_pname);
|
||||
|
||||
forigd = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
forigd = xbps_metadir_get_pkgd(xhp, pkgname);
|
||||
if (forigd == NULL) {
|
||||
xbps_dbg_printf(xhp, "%s-%s: conf_file %s not currently "
|
||||
"installed\n", pkgname, version, entry_pname);
|
||||
rv = 1;
|
||||
prop_object_release(forigd);
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -117,7 +116,6 @@ xbps_entry_install_conf_file(struct xbps_handle *xhp,
|
||||
}
|
||||
prop_object_iterator_release(iter2);
|
||||
}
|
||||
prop_object_release(forigd);
|
||||
/*
|
||||
* First case: original hash not found, install new file.
|
||||
*/
|
||||
|
@ -110,7 +110,7 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
|
||||
|
||||
pkgmetad = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
pkgmetad = xbps_metadir_get_pkgd(xhp, pkgname);
|
||||
assert(pkgmetad);
|
||||
|
||||
rv = xbps_pkg_exec_script(xhp, pkgmetad, "install-script", "post", update);
|
||||
@ -119,11 +119,8 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
errno, pkgname, version,
|
||||
"%s: [configure] INSTALL script failed to execute "
|
||||
"the post ACTION: %s", pkgver, strerror(rv));
|
||||
prop_object_release(pkgmetad);
|
||||
return rv;
|
||||
}
|
||||
prop_object_release(pkgmetad);
|
||||
|
||||
if (state == XBPS_PKG_STATE_INSTALLED)
|
||||
return rv;
|
||||
|
||||
|
106
lib/package_metadir.c
Normal file
106
lib/package_metadir.c
Normal file
@ -0,0 +1,106 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Juan Romero Pardines.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "xbps_api_impl.h"
|
||||
|
||||
void HIDDEN
|
||||
xbps_metadir_init(struct xbps_handle *xhp)
|
||||
{
|
||||
assert(xhp != NULL);
|
||||
|
||||
if (xhp->metadir_pool != NULL)
|
||||
return;
|
||||
|
||||
xhp->metadir_pool = prop_array_create();
|
||||
assert(xhp->metadir_pool);
|
||||
}
|
||||
|
||||
void HIDDEN
|
||||
xbps_metadir_release(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_object_t obj;
|
||||
unsigned int i;
|
||||
|
||||
if (xhp->metadir_pool == NULL)
|
||||
return;
|
||||
|
||||
for (i = 0; i < prop_array_count(xhp->metadir_pool); i++) {
|
||||
obj = prop_array_get(xhp->metadir_pool, i);
|
||||
prop_object_release(obj);
|
||||
}
|
||||
prop_object_release(xhp->metadir_pool);
|
||||
xhp->metadir_pool = NULL;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_metadir_get_pkgd(struct xbps_handle *xhp, const char *name)
|
||||
{
|
||||
prop_dictionary_t pkgd, opkgd;
|
||||
const char *savedpkgname;
|
||||
char *plistf;
|
||||
|
||||
assert(xhp);
|
||||
assert(name);
|
||||
|
||||
xbps_metadir_init(xhp);
|
||||
pkgd = xbps_find_pkg_in_array_by_name(xhp, xhp->metadir_pool,
|
||||
name, NULL);
|
||||
if (pkgd != NULL)
|
||||
return pkgd;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
opkgd = prop_dictionary_internalize_from_zfile(plistf);
|
||||
free(plistf);
|
||||
if (opkgd == NULL) {
|
||||
xbps_dbg_printf(xhp, "cannot read %s metadata: %s\n",
|
||||
savedpkgname, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop_array_add(xhp->metadir_pool, opkgd);
|
||||
return opkgd;
|
||||
}
|
@ -238,7 +238,7 @@ xbps_remove_pkg(struct xbps_handle *xhp,
|
||||
pkgver, xhp->rootdir, strerror(rv));
|
||||
goto out;
|
||||
}
|
||||
pkgd = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
pkgd = xbps_metadir_get_pkgd(xhp, pkgname);
|
||||
assert(pkgd);
|
||||
|
||||
/* If package was "half-removed", remove it fully. */
|
||||
@ -341,9 +341,6 @@ purge:
|
||||
/*
|
||||
* Remove package metadata plist.
|
||||
*/
|
||||
prop_object_release(pkgd);
|
||||
pkgd = NULL;
|
||||
|
||||
buf = xbps_xasprintf("%s/.%s.plist", xhp->metadir, pkgname);
|
||||
if (remove(buf) == -1) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REMOVE_FAIL,
|
||||
@ -373,8 +370,6 @@ out:
|
||||
free(buf);
|
||||
if (pkgver != NULL)
|
||||
free(pkgver);
|
||||
if (pkgd != NULL)
|
||||
prop_object_release(pkgd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
37
lib/plist.c
37
lib/plist.c
@ -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;
|
||||
}
|
||||
|
@ -97,12 +97,11 @@ compute_transaction_stats(struct xbps_handle *xhp)
|
||||
*/
|
||||
if ((strcmp(tract, "remove") == 0) ||
|
||||
(strcmp(tract, "update") == 0)) {
|
||||
pkg_metad = xbps_pkgd_from_metadir(xhp, pkgname);
|
||||
pkg_metad = xbps_metadir_get_pkgd(xhp, pkgname);
|
||||
if (pkg_metad == NULL)
|
||||
continue;
|
||||
prop_dictionary_get_uint64(pkg_metad,
|
||||
"installed_size", &tsize);
|
||||
prop_object_release(pkg_metad);
|
||||
rmsize += tsize;
|
||||
}
|
||||
if ((strcmp(tract, "install") == 0) ||
|
||||
|
Reference in New Issue
Block a user