Make xbps_(un)register_pkg() accept a boolean arg to flush regpkgdb on success.

This commit is contained in:
Juan RP 2011-12-28 05:57:04 +01:00
parent 11ca929985
commit a7f3a56e19
4 changed files with 23 additions and 23 deletions

View File

@ -56,7 +56,7 @@
*/
#define XBPS_PKGINDEX_VERSION "1.3"
#define XBPS_API_VERSION "20111224-2"
#define XBPS_API_VERSION "20111228"
#define XBPS_VERSION "0.12"
/**
@ -1153,20 +1153,24 @@ int xbps_array_replace_dict_by_name(prop_array_t array,
* @param[in] pkg_dict A dictionary with the following objects:
* \a pkgname, \a version, \a pkgver, \a short_desc (string),
* \a automatic-install (bool) and optionally \a provides (array of strings).
* @param[in] flush Set to true to make sure that regpkgdb plist
* is written to storage on success.
*
* @return 0 on success, otherwise an errno value.
*/
int xbps_register_pkg(prop_dictionary_t pkg_dict);
int xbps_register_pkg(prop_dictionary_t pkg_dict, bool flush);
/**
* Unregister a package from the package database.
*
* @param[in] pkgname Package name.
* @param[in] version Package version.
* @param[in] flush Set to true to make sure that regpkgdb plist
* is written to storage on success.
*
* @return 0 on success, otherwise an errno value.
*/
int xbps_unregister_pkg(const char *pkgname, const char *version);
int xbps_unregister_pkg(const char *pkgname, const char *version, bool flush);
/*@}*/

View File

@ -40,11 +40,11 @@
*/
int
xbps_register_pkg(prop_dictionary_t pkgrd)
xbps_register_pkg(prop_dictionary_t pkgrd, bool flush)
{
struct xbps_handle *xhp;
prop_dictionary_t pkgd;
prop_array_t provides, reqby, array;
prop_dictionary_t pkgd = NULL;
prop_array_t provides, reqby;
const char *pkgname, *version, *desc, *pkgver;
int rv = 0;
bool autoinst = false;
@ -116,12 +116,6 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
goto out;
}
}
array = prop_dictionary_get(xhp->regpkgdb, "packages");
rv = xbps_array_replace_dict_by_name(array, pkgd, pkgname);
if (rv != 0) {
prop_object_release(pkgd);
goto out;
}
/*
* Add the requiredby objects for dependent packages.
*/
@ -131,9 +125,13 @@ xbps_register_pkg(prop_dictionary_t pkgrd)
goto out;
}
}
prop_object_release(pkgd);
if (flush)
rv = xbps_regpkgdb_update(xhp, true);
out:
if (pkgd != NULL)
prop_object_release(pkgd);
if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REGISTER_FAIL,
rv, pkgname, version,
@ -145,27 +143,25 @@ out:
}
int
xbps_unregister_pkg(const char *pkgname, const char *version)
xbps_unregister_pkg(const char *pkgname, const char *version, bool flush)
{
struct xbps_handle *xhp;
int rv;
assert(pkgname != NULL);
xhp = xbps_handle_get();
if ((rv = xbps_regpkgdb_dictionary_init(xhp)) != 0)
return rv;
xbps_set_cb_state(XBPS_STATE_UNREGISTER, 0, pkgname, version, NULL);
if (!xbps_remove_pkg_from_dict_by_name(xhp->regpkgdb,
"packages", pkgname)) {
if (!xbps_regpkgdb_remove_pkgd(pkgname)) {
xbps_set_cb_state(XBPS_STATE_UNREGISTER_FAIL,
errno, pkgname, version,
"%s: failed to unregister package: %s",
pkgname, strerror(errno));
return errno;
}
if (flush) {
xhp = xbps_handle_get();
return xbps_regpkgdb_update(xhp, true);
}
return 0;
}

View File

@ -415,7 +415,7 @@ purge:
/*
* Unregister package from regpkgdb.
*/
if ((rv = xbps_unregister_pkg(pkgname, version)) != 0)
if ((rv = xbps_unregister_pkg(pkgname, version, false)) != 0)
goto out;
xbps_set_cb_state(XBPS_STATE_REMOVE_DONE,

View File

@ -266,7 +266,7 @@ xbps_transaction_commit(prop_dictionary_t transd)
/*
* Register package.
*/
if ((rv = xbps_register_pkg(obj)) != 0)
if ((rv = xbps_register_pkg(obj, false)) != 0)
goto out;
}
}