Make xbps_configure_pkg/packages accept a flush bool arg for frontends.

This commit is contained in:
Juan RP 2012-01-04 17:41:36 +01:00
parent 812005a7d9
commit a31c20e52a
5 changed files with 41 additions and 22 deletions

View File

@ -329,9 +329,9 @@ main(int argc, char **argv)
usage(xhp);
if (strcasecmp(argv[1], "all") == 0)
rv = xbps_configure_packages();
rv = xbps_configure_packages(true);
else
rv = xbps_configure_pkg(argv[1], NULL, true, false);
rv = xbps_configure_pkg(argv[1], NULL, true, false, true);
} else if (strcasecmp(argv[0], "show-deps") == 0) {
/*

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.3"
#define XBPS_API_VERSION "20111229"
#define XBPS_API_VERSION "20120104"
#define XBPS_VERSION "0.12"
/**
@ -608,20 +608,23 @@ struct xbps_handle *xbps_handle_get(void);
* @param[in] check_state Set it to true to check that package is
* in unpacked state.
* @param[in] update Set it to true if this package is being updated.
* @param[in] flush Set it to true to flush state to regpkgdb.
*
* @return 0 on success, otherwise an errno value.
*/
int xbps_configure_pkg(const char *pkgname,
const char *version,
bool check_state,
bool update);
bool update,
bool flush);
/**
* Configure (or force reconfiguration of) all packages.
* @param[in] flush Set it to true to flush state to regpkgdb.
*
* @return 0 on success, otherwise an errno value.
*/
int xbps_configure_packages(void);
int xbps_configure_packages(bool flush);
/*@}*/

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2009-2011 Juan Romero Pardines.
* Copyright (c) 2009-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -57,20 +57,28 @@ configure_pkgs_cb(prop_object_t obj, void *arg, bool *done)
prop_dictionary_get_cstring_nocopy(obj, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(obj, "version", &version);
return xbps_configure_pkg(pkgname, version, true, false);
return xbps_configure_pkg(pkgname, version, true, false, false);
}
int
xbps_configure_packages(void)
xbps_configure_packages(bool flush)
{
return xbps_regpkgdb_foreach_pkg_cb(configure_pkgs_cb, NULL);
struct xbps_handle *xhp = xbps_handle_get();
int rv;
rv = xbps_regpkgdb_foreach_pkg_cb(configure_pkgs_cb, &flush);
if (rv == 0)
rv = xbps_regpkgdb_update(xhp, true);
return rv;
}
int
xbps_configure_pkg(const char *pkgname,
const char *version,
bool check_state,
bool update)
bool update,
bool flush)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd;
@ -160,6 +168,8 @@ xbps_configure_pkg(const char *pkgname,
pkgver, strerror(rv));
}
free(pkgver);
if (flush)
rv = xbps_regpkgdb_update(xhp, true);
return rv;
}

View File

@ -1,5 +1,5 @@
/*-
* Copyright (c) 2008-2011 Juan Romero Pardines.
* Copyright (c) 2008-2012 Juan Romero Pardines.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -76,24 +76,24 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid version for %s\n", __func__, pkgname);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"pkgver", pkgver)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid pkgver for %s\n", __func__, pkgname);
rv = EINVAL;
goto out;
}
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"short_desc", desc)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid short_desc for %s\n", __func__, pkgname);
rv = EINVAL;
goto out;
}
if (reqby && !prop_dictionary_set(pkgd, "requiredby", reqby)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid requiredby for %s\n", __func__, pkgname);
rv = EINVAL;
goto out;
}
@ -105,13 +105,14 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
if (!prop_dictionary_set_bool(pkgd,
"automatic-install", autoinst)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid autoinst for %s\n", __func__, pkgname);
rv = EINVAL;
goto out;
}
if (provides) {
if (!prop_dictionary_set(pkgd, "provides", provides)) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: invalid provides for %s\n",
__func__, pkgname);
rv = EINVAL;
goto out;
}
@ -121,14 +122,18 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
*/
if (pkgrd && xbps_pkg_has_rundeps(pkgrd)) {
if ((rv = xbps_requiredby_pkg_add(xhp, pkgrd)) != 0) {
prop_object_release(pkgd);
xbps_dbg_printf("%s: requiredby add failed for %s\n",
__func__, pkgname);
goto out;
}
}
array = prop_dictionary_get(xhp->regpkgdb, "packages");
rv = xbps_array_replace_dict_by_name(array, pkgd, pkgname);
if (rv != 0)
if (rv != 0) {
xbps_dbg_printf("%s: failed to replace pkgd dict for %s\n",
__func__, pkgname);
goto out;
}
if (flush)
rv = xbps_regpkgdb_update(xhp, true);

View File

@ -224,7 +224,8 @@ xbps_transaction_commit(prop_dictionary_t transd)
/*
* Reconfigure pending package.
*/
rv = xbps_configure_pkg(pkgname, version, false, false);
rv = xbps_configure_pkg(pkgname, version,
false, false, false);
if (rv != 0)
goto out;
} else {
@ -305,7 +306,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
if (strcmp(tract, "update") == 0)
update = true;
rv = xbps_configure_pkg(pkgname, version, false, update);
rv = xbps_configure_pkg(pkgname, version, false, update, false);
if (rv != 0)
goto out;
/*