From a7f3a56e199110fed0e870a52dace590201e0b2f Mon Sep 17 00:00:00 2001 From: Juan RP Date: Wed, 28 Dec 2011 05:57:04 +0100 Subject: [PATCH] Make xbps_(un)register_pkg() accept a boolean arg to flush regpkgdb on success. --- include/xbps_api.h | 10 +++++++--- lib/package_register.c | 32 ++++++++++++++------------------ lib/package_remove.c | 2 +- lib/transaction_commit.c | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/include/xbps_api.h b/include/xbps_api.h index e004970a..c2363d3e 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -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); /*@}*/ diff --git a/lib/package_register.c b/lib/package_register.c index 1ef02f6d..c55d7f80 100644 --- a/lib/package_register.c +++ b/lib/package_register.c @@ -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; } diff --git a/lib/package_remove.c b/lib/package_remove.c index 75c3b92d..2f47f3de 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -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, diff --git a/lib/transaction_commit.c b/lib/transaction_commit.c index 3398f6bb..5f94648f 100644 --- a/lib/transaction_commit.c +++ b/lib/transaction_commit.c @@ -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; } }