Implemented plist caching, that gives >30% performance.

--HG--
extra : convert_revision : 6302893f967be96f99a86d499ca62a8c005e56f7
This commit is contained in:
Juan RP 2009-05-19 01:42:48 +02:00
parent 55f2f51b40
commit 38e6679ff5
7 changed files with 100 additions and 93 deletions

View file

@ -168,7 +168,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
prop_object_iterator_t iter; prop_object_iterator_t iter;
const char *instver, *origin, *pkgname, *version; const char *instver, *origin, *pkgname, *version;
int rv = 0; int rv = 0;
bool pkg_is_dep, doup = false; bool pkg_is_dep = false, doup = false;
/* /*
* Find and sort all required package dictionaries. * Find and sort all required package dictionaries.
@ -196,8 +196,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
array = prop_dictionary_get(props, "missing_deps"); array = prop_dictionary_get(props, "missing_deps");
if (prop_array_count(array) > 0) { if (prop_array_count(array) > 0) {
show_missing_deps(props, pkg); show_missing_deps(props, pkg);
prop_object_release(props); goto out;
exit(EXIT_FAILURE);
} }
prop_dictionary_get_cstring_nocopy(props, "origin", &origin); prop_dictionary_get_cstring_nocopy(props, "origin", &origin);
@ -205,14 +204,12 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
array = prop_dictionary_get(props, "packages"); array = prop_dictionary_get(props, "packages");
if (array == NULL || prop_array_count(array) == 0) { if (array == NULL || prop_array_count(array) == 0) {
printf("error: empty packages array!\n"); printf("error: empty packages array!\n");
prop_object_release(props); goto out;
exit(EXIT_FAILURE);
} }
iter = prop_array_iterator(array); iter = prop_array_iterator(array);
if (iter == NULL) { if (iter == NULL) {
printf("error: allocating array mem! (%s)\n", strerror(errno)); printf("error: allocating array mem! (%s)\n", strerror(errno));
prop_object_release(props); goto out;
exit(EXIT_FAILURE);
} }
/* /*
* Show download/installed size for the transaction. * Show download/installed size for the transaction.
@ -225,8 +222,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
if (force == false) { if (force == false) {
if (xbps_noyes("Do you want to continue?") == false) { if (xbps_noyes("Do you want to continue?") == false) {
printf("Aborting!\n"); printf("Aborting!\n");
prop_object_release(props); goto out2;
exit(EXIT_SUCCESS);
} }
} }
@ -252,8 +248,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
if (instpkg == NULL) { if (instpkg == NULL) {
printf("error: unable to find %s installed " printf("error: unable to find %s installed "
"dict!\n", pkgname); "dict!\n", pkgname);
prop_object_release(props); goto out2;
exit(EXIT_FAILURE);
} }
prop_dictionary_get_cstring_nocopy(instpkg, prop_dictionary_get_cstring_nocopy(instpkg,
@ -265,8 +260,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
if (rv != 0) { if (rv != 0) {
printf("error: removing %s-%s (%s)\n", printf("error: removing %s-%s (%s)\n",
pkgname, instver, strerror(rv)); pkgname, instver, strerror(rv));
prop_object_release(props); goto out2;
exit(EXIT_FAILURE);
} }
} else { } else {
@ -279,8 +273,7 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
if ((rv = xbps_unpack_binary_pkg(obj)) != 0) { if ((rv = xbps_unpack_binary_pkg(obj)) != 0) {
printf("error: unpacking %s-%s (%s)\n", pkgname, printf("error: unpacking %s-%s (%s)\n", pkgname,
version, strerror(rv)); version, strerror(rv));
prop_object_release(props); goto out2;
exit(EXIT_FAILURE);
} }
/* /*
* Register binary package. * Register binary package.
@ -291,13 +284,18 @@ xbps_install_pkg(const char *pkg, bool force, bool update)
if ((rv = xbps_register_pkg(obj, doup, pkg_is_dep)) != 0) { if ((rv = xbps_register_pkg(obj, doup, pkg_is_dep)) != 0) {
printf("error: registering %s-%s! (%s)\n", printf("error: registering %s-%s! (%s)\n",
pkgname, version, strerror(rv)); pkgname, version, strerror(rv));
prop_object_release(props); goto out2;
exit(EXIT_FAILURE);
} }
pkg_is_dep = false; pkg_is_dep = false;
} }
out2:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
out:
prop_object_release(props); prop_object_release(props);
xbps_release_repolist_data();
xbps_release_regpkgdb_dict();
if (rv != 0)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -312,7 +310,7 @@ xbps_autoupdate_pkgs(bool force)
const char *pkgname, *version, *instver; const char *pkgname, *version, *instver;
int rv = 0; int rv = 0;
dict = xbps_get_regpkgdb_dict(); dict = xbps_prepare_regpkgdb_dict();
if (dict == NULL) { if (dict == NULL) {
printf("No packages currently installed (%s).\n", printf("No packages currently installed (%s).\n",
strerror(errno)); strerror(errno));
@ -321,15 +319,12 @@ xbps_autoupdate_pkgs(bool force)
iter = xbps_get_array_iter_from_dict(dict, "packages"); iter = xbps_get_array_iter_from_dict(dict, "packages");
if (iter == NULL) { if (iter == NULL) {
xbps_release_regpkgdb_dict(); rv = EINVAL;
exit(EXIT_FAILURE); goto out;
} }
if (xbps_prepare_repolist_data() != 0) { if ((rv = xbps_prepare_repolist_data()) != 0)
prop_object_iterator_release(iter); goto out;
xbps_release_regpkgdb_dict();
exit(EXIT_FAILURE);
}
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
@ -338,7 +333,6 @@ xbps_autoupdate_pkgs(bool force)
break; break;
} }
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
xbps_release_regpkgdb_dict();
/* Sort the list of packages */ /* Sort the list of packages */
props = xbps_get_pkg_props(); props = xbps_get_pkg_props();
@ -349,25 +343,25 @@ xbps_autoupdate_pkgs(bool force)
} }
printf("Error while checking for new pkgs: %s\n", printf("Error while checking for new pkgs: %s\n",
strerror(errno)); strerror(errno));
exit(EXIT_FAILURE); goto out;
} }
if ((rv = xbps_sort_pkg_deps(props)) != 0) { if ((rv = xbps_sort_pkg_deps(props)) != 0) {
printf("Error while sorting packages: %s\n", printf("Error while sorting packages: %s\n",
strerror(rv)); strerror(rv));
exit(EXIT_FAILURE); goto out;
} }
/* Update all packages now */ /* Update all packages now */
array = prop_dictionary_get(props, "packages"); array = prop_dictionary_get(props, "packages");
if (array == NULL || prop_array_count(array) == 0) { if (array == NULL || prop_array_count(array) == 0) {
printf("error: empty packages array!\n"); printf("error: empty packages array!\n");
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out;
} }
iter = prop_array_iterator(array); iter = prop_array_iterator(array);
if (iter == NULL) { if (iter == NULL) {
printf("error: allocating array mem! (%s)\n", strerror(errno)); printf("error: allocating array mem! (%s)\n", strerror(errno));
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out;
} }
/* /*
@ -382,7 +376,7 @@ xbps_autoupdate_pkgs(bool force)
if (xbps_noyes("Do you want to continue?") == false) { if (xbps_noyes("Do you want to continue?") == false) {
printf("Aborting!\n"); printf("Aborting!\n");
prop_object_release(props); prop_object_release(props);
exit(EXIT_SUCCESS); goto out2;
} }
} }
@ -403,7 +397,7 @@ xbps_autoupdate_pkgs(bool force)
printf("error: unable to find %s installed " printf("error: unable to find %s installed "
"dict!\n", pkgname); "dict!\n", pkgname);
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out2;
} }
prop_dictionary_get_cstring_nocopy(instpkg, prop_dictionary_get_cstring_nocopy(instpkg,
@ -416,7 +410,7 @@ xbps_autoupdate_pkgs(bool force)
printf("error: removing %s-%s (%s)\n", printf("error: removing %s-%s (%s)\n",
pkgname, instver, strerror(rv)); pkgname, instver, strerror(rv));
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out2;
} }
/* /*
@ -426,7 +420,7 @@ xbps_autoupdate_pkgs(bool force)
printf("error: unpacking %s-%s (%s)\n", pkgname, printf("error: unpacking %s-%s (%s)\n", pkgname,
version, strerror(rv)); version, strerror(rv));
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out2;
} }
/* /*
* Register binary package. * Register binary package.
@ -435,10 +429,17 @@ xbps_autoupdate_pkgs(bool force)
printf("error: registering %s-%s! (%s)\n", printf("error: registering %s-%s! (%s)\n",
pkgname, version, strerror(rv)); pkgname, version, strerror(rv));
prop_object_release(props); prop_object_release(props);
exit(EXIT_FAILURE); goto out2;
} }
} }
out2:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
out:
xbps_release_repolist_data(); xbps_release_repolist_data();
xbps_release_regpkgdb_dict();
if (rv != 0)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View file

@ -100,8 +100,6 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
const char *rootdir;
char *plist;
int c, flags = 0, rv = 0; int c, flags = 0, rv = 0;
bool chkhash = false, force = false, verbose = false; bool chkhash = false, force = false, verbose = false;
@ -136,32 +134,30 @@ main(int argc, char **argv)
if (flags != 0) if (flags != 0)
xbps_set_flags(flags); xbps_set_flags(flags);
if ((dict = xbps_prepare_regpkgdb_dict()) == NULL) {
if (errno != ENOENT) {
rv = errno;
printf("Couldn't initialized regpkgdb dict: %s\n",
strerror(errno));
goto out;
}
}
if (strcasecmp(argv[0], "list") == 0) { if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */ /* Lists packages currently registered in database. */
if (argc != 1) if (argc != 1)
usage(); usage();
rootdir = xbps_get_rootdir();
plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (plist == NULL)
exit(EXIT_FAILURE);
dict = prop_dictionary_internalize_from_file(plist);
if (dict == NULL) { if (dict == NULL) {
printf("No packages currently registered.\n"); printf("No packages currently installed.\n");
free(plist); goto out;
exit(EXIT_SUCCESS);
} }
if (!xbps_callback_array_iter_in_dict(dict, "packages", if (!xbps_callback_array_iter_in_dict(dict, "packages",
list_pkgs_in_dict, NULL)) { list_pkgs_in_dict, NULL)) {
prop_object_release(dict); rv = errno;
free(plist); goto out;
exit(EXIT_FAILURE);
} }
prop_object_release(dict);
free(plist);
} else if (strcasecmp(argv[0], "install") == 0) { } else if (strcasecmp(argv[0], "install") == 0) {
/* Installs a binary package and required deps. */ /* Installs a binary package and required deps. */
@ -230,5 +226,10 @@ main(int argc, char **argv)
usage(); usage();
} }
out:
xbps_release_regpkgdb_dict();
if (rv != 0)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View file

@ -64,7 +64,7 @@ xbps_autoremove_pkgs(void)
iter = prop_array_iterator(orphans); iter = prop_array_iterator(orphans);
if (iter == NULL) if (iter == NULL)
exit(EXIT_FAILURE); goto out;
printf("The following packages were installed automatically\n" printf("The following packages were installed automatically\n"
"(as dependencies) and aren't needed anymore:\n\n"); "(as dependencies) and aren't needed anymore:\n\n");
@ -88,7 +88,7 @@ xbps_autoremove_pkgs(void)
if (xbps_noyes("Do you want to remove them?") == false) { if (xbps_noyes("Do you want to remove them?") == false) {
printf("Cancelled!\n"); printf("Cancelled!\n");
exit(EXIT_SUCCESS); goto out2;
} }
while ((obj = prop_object_iterator_next(iter)) != NULL) { while ((obj = prop_object_iterator_next(iter)) != NULL) {
@ -96,14 +96,15 @@ xbps_autoremove_pkgs(void)
prop_dictionary_get_cstring_nocopy(obj, "version", &version); prop_dictionary_get_cstring_nocopy(obj, "version", &version);
printf("Removing package %s-%s ...\n", pkgname, version); printf("Removing package %s-%s ...\n", pkgname, version);
if ((rv = xbps_remove_binary_pkg(pkgname, false)) != 0) { if ((rv = xbps_remove_binary_pkg(pkgname, false)) != 0)
goto out2;
}
out2:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
out:
prop_object_release(orphans); prop_object_release(orphans);
if (rv != 0)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
}
}
prop_object_iterator_release(iter);
prop_object_release(orphans);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
@ -122,7 +123,7 @@ xbps_remove_pkg(const char *pkgname, bool force)
dict = xbps_find_pkg_installed_from_plist(pkgname); dict = xbps_find_pkg_installed_from_plist(pkgname);
if (dict == NULL) { if (dict == NULL) {
printf("Package %s is not installed.\n", pkgname); printf("Package %s is not installed.\n", pkgname);
exit(EXIT_FAILURE); goto out;
} }
prop_dictionary_get_cstring_nocopy(dict, "version", &version); prop_dictionary_get_cstring_nocopy(dict, "version", &version);
@ -136,7 +137,7 @@ xbps_remove_pkg(const char *pkgname, bool force)
if (!force) { if (!force) {
if (!xbps_noyes("Do you want to remove %s?", pkgname)) { if (!xbps_noyes("Do you want to remove %s?", pkgname)) {
printf("Cancelling!\n"); printf("Cancelling!\n");
exit(EXIT_SUCCESS); goto out;
} }
} }
printf("Forcing %s-%s for deletion!\n", pkgname, version); printf("Forcing %s-%s for deletion!\n", pkgname, version);
@ -144,7 +145,7 @@ xbps_remove_pkg(const char *pkgname, bool force)
if (!force) { if (!force) {
if (!xbps_noyes("Do you want to remove %s?", pkgname)) { if (!xbps_noyes("Do you want to remove %s?", pkgname)) {
printf("Cancelling!\n"); printf("Cancelling!\n");
exit(EXIT_SUCCESS); goto out;
} }
} }
} }
@ -153,11 +154,14 @@ xbps_remove_pkg(const char *pkgname, bool force)
if ((rv = xbps_remove_binary_pkg(pkgname, false)) != 0) { if ((rv = xbps_remove_binary_pkg(pkgname, false)) != 0) {
printf("Unable to remove %s-%s (%s).\n", printf("Unable to remove %s-%s (%s).\n",
pkgname, version, strerror(errno)); pkgname, version, strerror(errno));
prop_object_release(dict); goto out;
exit(EXIT_FAILURE);
} }
printf("Package %s-%s removed successfully.\n", pkgname, version); printf("Package %s-%s removed successfully.\n", pkgname, version);
prop_object_release(dict);
out:
xbps_release_regpkgdb_dict();
if (rv != 0)
exit(EXIT_FAILURE);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View file

@ -41,8 +41,6 @@ xbps-bin:
libxbps: libxbps:
* Fix glibc updates: removing libc is bad. * Fix glibc updates: removing libc is bad.
* When accessing .plist files, only internalize_from_file once to
avoid multiple open(3) and fstat(3) calls. [IN PROGRESS]
* Create xbps_upgrade_pkg() to replace or remove/unpack and register. * Create xbps_upgrade_pkg() to replace or remove/unpack and register.
Remove duplicate code from xbps-bin/install.c. [IN PROGRESS] Remove duplicate code from xbps-bin/install.c. [IN PROGRESS]
* Add support to upgrade packages but overwritting current files; * Add support to upgrade packages but overwritting current files;

View file

@ -130,7 +130,7 @@ prop_dictionary_t xbps_find_pkg_from_plist(const char *, const char *);
prop_dictionary_t xbps_find_pkg_installed_from_plist(const char *); prop_dictionary_t xbps_find_pkg_installed_from_plist(const char *);
bool xbps_find_string_in_array(prop_array_t, const char *); bool xbps_find_string_in_array(prop_array_t, const char *);
prop_dictionary_t xbps_get_regpkgdb_dict(void); prop_dictionary_t xbps_prepare_regpkgdb_dict(void);
void xbps_release_regpkgdb_dict(void); void xbps_release_regpkgdb_dict(void);
prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t, prop_object_iterator_t xbps_get_array_iter_from_dict(prop_dictionary_t,
const char *); const char *);

View file

@ -35,17 +35,15 @@
#include <xbps_api.h> #include <xbps_api.h>
static prop_dictionary_t pkg_props; static prop_dictionary_t pkg_props;
static bool pkg_props_initialized;
static int static int
create_pkg_props_dictionary(void) create_pkg_props_dictionary(void)
{ {
prop_array_t unsorted, missing; prop_array_t unsorted, missing;
int rv = 0; int rv = 0;
static bool pkg_props_avail;
assert(pkgname != NULL); if (pkg_props_initialized)
if (pkg_props_avail)
return 0; return 0;
pkg_props = prop_dictionary_create(); pkg_props = prop_dictionary_create();
@ -73,7 +71,7 @@ create_pkg_props_dictionary(void)
goto fail3; goto fail3;
} }
pkg_props_avail = true; pkg_props_initialized = true;
return rv; return rv;
@ -90,7 +88,7 @@ fail:
prop_dictionary_t prop_dictionary_t
xbps_get_pkg_props(void) xbps_get_pkg_props(void)
{ {
if (pkg_props == NULL || prop_dictionary_count(pkg_props) == 0) if (pkg_props_initialized == false)
return NULL; return NULL;
return prop_dictionary_copy(pkg_props); return prop_dictionary_copy(pkg_props);
@ -107,18 +105,12 @@ xbps_prepare_repolist_data(void)
const char *rootdir; const char *rootdir;
char *plist; char *plist;
int rv = 0; int rv = 0;
static bool repodata_init; static bool repodata_initialized;
if (repodata_initialized)
return 0;
if (repodata_init == false) {
SIMPLEQ_INIT(&repodata_queue); SIMPLEQ_INIT(&repodata_queue);
repodata_init = true;
}
rdata = malloc(sizeof(struct repository_data));
if (rdata == NULL) {
rv = errno;
goto out;
}
rootdir = xbps_get_rootdir(); rootdir = xbps_get_rootdir();
if (rootdir == NULL) if (rootdir == NULL)
@ -163,6 +155,12 @@ xbps_prepare_repolist_data(void)
goto out2; goto out2;
} }
rdata = malloc(sizeof(struct repository_data));
if (rdata == NULL) {
rv = errno;
goto out2;
}
rdata->rd_repod = prop_dictionary_internalize_from_file(plist); rdata->rd_repod = prop_dictionary_internalize_from_file(plist);
if (rdata->rd_repod == NULL) { if (rdata->rd_repod == NULL) {
free(plist); free(plist);
@ -173,6 +171,8 @@ xbps_prepare_repolist_data(void)
SIMPLEQ_INSERT_TAIL(&repodata_queue, rdata, chain); SIMPLEQ_INSERT_TAIL(&repodata_queue, rdata, chain);
} }
repodata_initialized = true;
out2: out2:
prop_object_iterator_release(iter); prop_object_iterator_release(iter);
out: out:

View file

@ -34,6 +34,7 @@
#include <xbps_api.h> #include <xbps_api.h>
static prop_dictionary_t regpkgdb_dict; static prop_dictionary_t regpkgdb_dict;
static bool regpkgdb_initialized;
bool bool
xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj, xbps_add_obj_to_dict(prop_dictionary_t dict, prop_object_t obj,
@ -162,16 +163,16 @@ xbps_find_pkg_from_plist(const char *plist, const char *pkgname)
prop_dictionary_t prop_dictionary_t
xbps_find_pkg_installed_from_plist(const char *pkgname) xbps_find_pkg_installed_from_plist(const char *pkgname)
{ {
prop_dictionary_t instd, pkgd; prop_dictionary_t pkgd;
instd = xbps_get_regpkgdb_dict(); if (regpkgdb_initialized == false)
if (instd == NULL)
return NULL; return NULL;
pkgd = xbps_find_pkg_in_dict(instd, "packages", pkgname); pkgd = xbps_find_pkg_in_dict(regpkgdb_dict, "packages", pkgname);
xbps_release_regpkgdb_dict(); if (pkgd == NULL)
return NULL;
return pkgd; return prop_dictionary_copy(pkgd);
} }
prop_dictionary_t prop_dictionary_t
@ -201,12 +202,12 @@ xbps_find_pkg_in_dict(prop_dictionary_t dict, const char *key,
} }
prop_dictionary_t prop_dictionary_t
xbps_get_regpkgdb_dict(void) xbps_prepare_regpkgdb_dict(void)
{ {
const char *rootdir; const char *rootdir;
char *plist; char *plist;
if (regpkgdb_dict == NULL) { if (regpkgdb_initialized == false) {
rootdir = xbps_get_rootdir(); rootdir = xbps_get_rootdir();
plist = xbps_xasprintf("%s/%s/%s", rootdir, plist = xbps_xasprintf("%s/%s/%s", rootdir,
XBPS_META_PATH, XBPS_REGPKGDB); XBPS_META_PATH, XBPS_REGPKGDB);
@ -219,6 +220,7 @@ xbps_get_regpkgdb_dict(void)
return NULL; return NULL;
} }
free(plist); free(plist);
regpkgdb_initialized = true;
} }
return prop_dictionary_copy(regpkgdb_dict); return prop_dictionary_copy(regpkgdb_dict);
@ -227,11 +229,12 @@ xbps_get_regpkgdb_dict(void)
void void
xbps_release_regpkgdb_dict(void) xbps_release_regpkgdb_dict(void)
{ {
if (regpkgdb_dict == NULL) if (regpkgdb_initialized == false)
return; return;
prop_object_release(regpkgdb_dict); prop_object_release(regpkgdb_dict);
regpkgdb_dict = NULL; regpkgdb_dict = NULL;
regpkgdb_initialized = false;
} }
bool bool