Improve marginally configuring/purging all packages by looking at its

state in the object dictionary rather than opening and externalizing
the dictionary of every package.

--HG--
extra : convert_revision : xtraeme%40gmail.com-20090821093126-0xw980x0pqtq59q2
This commit is contained in:
Juan RP 2009-08-21 11:31:26 +02:00
parent 4aac305105
commit ecfa25833f
5 changed files with 105 additions and 56 deletions

View File

@ -415,7 +415,7 @@ exec_transaction(struct transaction *trans)
*/ */
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) { while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname); prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_configure_pkg(pkgname)) != 0) { if ((rv = xbps_configure_pkg(pkgname, false)) != 0) {
printf("Error configuring package %s (%s)\n", printf("Error configuring package %s (%s)\n",
pkgname, strerror(rv)); pkgname, strerror(rv));
return rv; return rv;

View File

@ -87,9 +87,6 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
prop_object_t obj;
prop_object_iterator_t iter;
const char *curpkgname;
int c, flags = 0, rv = 0; int c, flags = 0, rv = 0;
bool force = false, verbose = false; bool force = false, verbose = false;
@ -224,21 +221,10 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
if (strcasecmp(argv[1], "all") == 0) { if (strcasecmp(argv[1], "all") == 0)
iter = xbps_get_array_iter_from_dict(dict, "packages"); rv = xbps_purge_all_pkgs();
if (iter == NULL) else
goto out; rv = xbps_purge_pkg(argv[1], true);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &curpkgname);
if ((rv = xbps_purge_pkg(curpkgname)) != 0)
break;
}
prop_object_iterator_release(iter);
} else {
rv = xbps_purge_pkg(argv[1]);
}
} else if (strcasecmp(argv[0], "reconfigure") == 0) { } else if (strcasecmp(argv[0], "reconfigure") == 0) {
/* /*
@ -247,21 +233,10 @@ main(int argc, char **argv)
if (argc != 2) if (argc != 2)
usage(); usage();
if (strcasecmp(argv[1], "all") == 0) { if (strcasecmp(argv[1], "all") == 0)
iter = xbps_get_array_iter_from_dict(dict, "packages"); rv = xbps_configure_all_pkgs();
if (iter == NULL) else
goto out; rv = xbps_configure_pkg(argv[1], true);
while ((obj = prop_object_iterator_next(iter))) {
prop_dictionary_get_cstring_nocopy(obj,
"pkgname", &curpkgname);
if ((rv = xbps_configure_pkg(curpkgname)) != 0)
break;
}
prop_object_iterator_release(iter);
} else {
rv = xbps_configure_pkg(argv[1]);
}
} else { } else {
usage(); usage();

View File

@ -68,7 +68,8 @@
#endif #endif
/* From lib/configure.c */ /* From lib/configure.c */
int xbps_configure_pkg(const char *); int xbps_configure_pkg(const char *, bool);
int xbps_configure_all_pkgs(void);
/* from lib/cmpver.c */ /* from lib/cmpver.c */
int xbps_cmpver(const char *, const char *); int xbps_cmpver(const char *, const char *);
@ -145,7 +146,8 @@ int xbps_remove_pkg_from_dict(prop_dictionary_t, const char *,
int xbps_remove_string_from_array(prop_array_t, const char *); int xbps_remove_string_from_array(prop_array_t, const char *);
/* From lib/purge.c */ /* From lib/purge.c */
int xbps_purge_pkg(const char *); int xbps_purge_pkg(const char *, bool);
int xbps_purge_all_pkgs(void);
/* From lib/register.c */ /* From lib/register.c */
int xbps_register_pkg(prop_dictionary_t, bool); int xbps_register_pkg(prop_dictionary_t, bool);

View File

@ -31,12 +31,47 @@
#include <xbps_api.h> #include <xbps_api.h>
/* /*
* Configure a package that is currently unpacked. This * Configure all packages currently in unpacked state.
* runs the post INSTALL action if required and updates the
* package state to installed.
*/ */
int int
xbps_configure_pkg(const char *pkgname) xbps_configure_all_pkgs(void)
{
prop_dictionary_t d;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname;
int rv = 0;
pkg_state_t state = 0;
d = xbps_prepare_regpkgdb_dict();
if (d == NULL)
return ENODEV;
iter = xbps_get_array_iter_from_dict(d, "packages");
if (iter == NULL)
return ENOENT;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_UNPACKED)
continue;
if ((rv = xbps_configure_pkg(pkgname, false)) != 0)
break;
}
prop_object_iterator_release(iter);
return rv;
}
/*
* Configure a package that is in unpacked state. This runs the
* post INSTALL action if required and updates package state to
* to installed.
*/
int
xbps_configure_pkg(const char *pkgname, bool check_state)
{ {
prop_dictionary_t pkgd; prop_dictionary_t pkgd;
const char *rootdir, *version; const char *rootdir, *version;
@ -50,6 +85,7 @@ xbps_configure_pkg(const char *pkgname)
rootdir = xbps_get_rootdir(); rootdir = xbps_get_rootdir();
flags = xbps_get_flags(); flags = xbps_get_flags();
if (check_state) {
if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0) if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0)
return rv; return rv;
@ -60,6 +96,7 @@ xbps_configure_pkg(const char *pkgname)
reconfigure = true; reconfigure = true;
} else if (state != XBPS_PKG_STATE_UNPACKED) } else if (state != XBPS_PKG_STATE_UNPACKED)
return EINVAL; return EINVAL;
}
pkgd = xbps_find_pkg_installed_from_plist(pkgname); pkgd = xbps_find_pkg_installed_from_plist(pkgname);
if (pkgd == NULL) if (pkgd == NULL)

View File

@ -33,13 +33,46 @@
static int remove_pkg_metadata(const char *); static int remove_pkg_metadata(const char *);
int
xbps_purge_all_pkgs(void)
{
prop_dictionary_t d;
prop_object_t obj;
prop_object_iterator_t iter;
const char *pkgname;
int rv = 0;
pkg_state_t state = 0;
d = xbps_prepare_regpkgdb_dict();
if (d == NULL)
return ENODEV;
iter = xbps_get_array_iter_from_dict(d, "packages");
if (iter == NULL)
return ENOENT;
while ((obj = prop_object_iterator_next(iter)) != NULL) {
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
if ((rv = xbps_get_pkg_state_dictionary(obj, &state)) != 0)
break;
if (state != XBPS_PKG_STATE_CONFIG_FILES)
continue;
if ((rv = xbps_purge_pkg(pkgname, false)) != 0)
break;
}
prop_object_iterator_release(iter);
return rv;
}
/* /*
* Purge a package that is currently in "config-files" state. * Purge a package that is currently in "config-files" state.
* This removes configuration files if they weren't modified, * This removes configuration files if they weren't modified,
* removes metadata files and fully unregisters the package. * removes metadata files and fully unregisters the package.
*/ */
int int
xbps_purge_pkg(const char *pkgname) xbps_purge_pkg(const char *pkgname, bool check_state)
{ {
prop_dictionary_t dict; prop_dictionary_t dict;
prop_array_t array; prop_array_t array;
@ -54,6 +87,7 @@ xbps_purge_pkg(const char *pkgname)
rootdir = xbps_get_rootdir(); rootdir = xbps_get_rootdir();
flags = xbps_get_flags(); flags = xbps_get_flags();
if (check_state) {
/* /*
* Skip packages that aren't in "config-files" state. * Skip packages that aren't in "config-files" state.
*/ */
@ -62,6 +96,7 @@ xbps_purge_pkg(const char *pkgname)
if (state != XBPS_PKG_STATE_CONFIG_FILES) if (state != XBPS_PKG_STATE_CONFIG_FILES)
return 0; return 0;
}
/* /*
* Iterate over the pkg file list dictionary and remove all * Iterate over the pkg file list dictionary and remove all