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:
parent
4aac305105
commit
ecfa25833f
@ -415,7 +415,7 @@ exec_transaction(struct transaction *trans)
|
||||
*/
|
||||
while ((obj = prop_object_iterator_next(trans->iter)) != NULL) {
|
||||
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",
|
||||
pkgname, strerror(rv));
|
||||
return rv;
|
||||
|
@ -87,9 +87,6 @@ int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_object_t obj;
|
||||
prop_object_iterator_t iter;
|
||||
const char *curpkgname;
|
||||
int c, flags = 0, rv = 0;
|
||||
bool force = false, verbose = false;
|
||||
|
||||
@ -224,21 +221,10 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0) {
|
||||
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
||||
if (iter == NULL)
|
||||
goto out;
|
||||
|
||||
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]);
|
||||
}
|
||||
if (strcasecmp(argv[1], "all") == 0)
|
||||
rv = xbps_purge_all_pkgs();
|
||||
else
|
||||
rv = xbps_purge_pkg(argv[1], true);
|
||||
|
||||
} else if (strcasecmp(argv[0], "reconfigure") == 0) {
|
||||
/*
|
||||
@ -247,21 +233,10 @@ main(int argc, char **argv)
|
||||
if (argc != 2)
|
||||
usage();
|
||||
|
||||
if (strcasecmp(argv[1], "all") == 0) {
|
||||
iter = xbps_get_array_iter_from_dict(dict, "packages");
|
||||
if (iter == NULL)
|
||||
goto out;
|
||||
|
||||
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]);
|
||||
}
|
||||
if (strcasecmp(argv[1], "all") == 0)
|
||||
rv = xbps_configure_all_pkgs();
|
||||
else
|
||||
rv = xbps_configure_pkg(argv[1], true);
|
||||
|
||||
} else {
|
||||
usage();
|
||||
|
@ -68,7 +68,8 @@
|
||||
#endif
|
||||
|
||||
/* 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 */
|
||||
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 *);
|
||||
|
||||
/* 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 */
|
||||
int xbps_register_pkg(prop_dictionary_t, bool);
|
||||
|
@ -31,12 +31,47 @@
|
||||
#include <xbps_api.h>
|
||||
|
||||
/*
|
||||
* Configure a package that is currently unpacked. This
|
||||
* runs the post INSTALL action if required and updates the
|
||||
* package state to installed.
|
||||
* Configure all packages currently in unpacked state.
|
||||
*/
|
||||
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;
|
||||
const char *rootdir, *version;
|
||||
@ -50,6 +85,7 @@ xbps_configure_pkg(const char *pkgname)
|
||||
rootdir = xbps_get_rootdir();
|
||||
flags = xbps_get_flags();
|
||||
|
||||
if (check_state) {
|
||||
if ((rv = xbps_get_pkg_state_installed(pkgname, &state)) != 0)
|
||||
return rv;
|
||||
|
||||
@ -60,6 +96,7 @@ xbps_configure_pkg(const char *pkgname)
|
||||
reconfigure = true;
|
||||
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
||||
return EINVAL;
|
||||
}
|
||||
|
||||
pkgd = xbps_find_pkg_installed_from_plist(pkgname);
|
||||
if (pkgd == NULL)
|
||||
|
37
lib/purge.c
37
lib/purge.c
@ -33,13 +33,46 @@
|
||||
|
||||
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.
|
||||
* This removes configuration files if they weren't modified,
|
||||
* removes metadata files and fully unregisters the package.
|
||||
*/
|
||||
int
|
||||
xbps_purge_pkg(const char *pkgname)
|
||||
xbps_purge_pkg(const char *pkgname, bool check_state)
|
||||
{
|
||||
prop_dictionary_t dict;
|
||||
prop_array_t array;
|
||||
@ -54,6 +87,7 @@ xbps_purge_pkg(const char *pkgname)
|
||||
rootdir = xbps_get_rootdir();
|
||||
flags = xbps_get_flags();
|
||||
|
||||
if (check_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)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Iterate over the pkg file list dictionary and remove all
|
||||
|
Loading…
Reference in New Issue
Block a user