diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index a475e65f..a0a89d6d 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -117,7 +117,7 @@ main(int argc, char **argv) struct xbps_handle xh; struct xferstat xfer; const char *pkgn, *version, *rootdir = NULL, *confdir = NULL; - char *plist, *pkgname, *pkgver, *in_chroot_env, *hash; + char *plist, *pkgname, *in_chroot_env, *hash; bool in_chroot = false; int flags = 0, i, c, rv = 0; @@ -186,12 +186,6 @@ main(int argc, char **argv) prop_dictionary_set_cstring_nocopy(dict, "pkgname", argv[1]); prop_dictionary_set_cstring_nocopy(dict, "version", argv[2]); prop_dictionary_set_cstring_nocopy(dict, "short_desc", argv[3]); - pkgver = xbps_xasprintf("%s-%s", argv[1], argv[2]); - if (pkgver == NULL) { - rv = -1; - goto out; - } - prop_dictionary_set_cstring(dict, "pkgver", pkgver); prop_dictionary_set_bool(dict, "automatic-install", false); pkgd = xbps_pkgdb_get_pkgd(argv[1], false); @@ -207,7 +201,7 @@ main(int argc, char **argv) pkgn, version, MSG_RESET); } else { rv = xbps_set_pkg_state_installed(argv[1], argv[2], - pkgver, XBPS_PKG_STATE_INSTALLED); + XBPS_PKG_STATE_INSTALLED); if (rv != 0) goto out; @@ -223,7 +217,6 @@ main(int argc, char **argv) argv[1], argv[2], MSG_RESET); } } - free(pkgver); prop_object_release(dict); } else if (strcasecmp(argv[0], "unregister") == 0) { /* Unregisters a package from the database */ diff --git a/include/xbps_api.h b/include/xbps_api.h index 2a39fdb8..1203779b 100644 --- a/include/xbps_api.h +++ b/include/xbps_api.h @@ -56,8 +56,8 @@ */ #define XBPS_PKGINDEX_VERSION "1.4" -#define XBPS_API_VERSION "20120405" -#define XBPS_VERSION "0.15" +#define XBPS_API_VERSION "20120410" +#define XBPS_VERSION "0.16" /** * @def XBPS_RELVER @@ -1677,15 +1677,13 @@ int xbps_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t *state); * Sets package state \a state in package \a pkgname. * * @param[in] pkgname Package name. - * @param[in] version Package version (optional). - * @param[in] pkgver Package name/version (optional). + * @param[in] version Package version. * @param[in] state Package state to be set. * * @return 0 on success, otherwise an errno value. */ int xbps_set_pkg_state_installed(const char *pkgname, const char *version, - const char *pkgver, pkg_state_t state); /** diff --git a/lib/package_configure.c b/lib/package_configure.c index 163d06a4..60ab5879 100644 --- a/lib/package_configure.c +++ b/lib/package_configure.c @@ -163,7 +163,7 @@ xbps_configure_pkg(const char *pkgname, } } free(buf); - rv = xbps_set_pkg_state_installed(pkgname, lver, pkgver, + rv = xbps_set_pkg_state_installed(pkgname, lver, XBPS_PKG_STATE_INSTALLED); if (rv != 0) { xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv, diff --git a/lib/package_remove.c b/lib/package_remove.c index 854b25f4..a776d16c 100644 --- a/lib/package_remove.c +++ b/lib/package_remove.c @@ -375,7 +375,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update) /* * Set package state to "half-removed". */ - rv = xbps_set_pkg_state_installed(pkgname, version, pkgver, + rv = xbps_set_pkg_state_installed(pkgname, version, XBPS_PKG_STATE_HALF_REMOVED); if (rv != 0) { xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, diff --git a/lib/package_state.c b/lib/package_state.c index fd1a1168..93e97aad 100644 --- a/lib/package_state.c +++ b/lib/package_state.c @@ -133,22 +133,24 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state) } static int -set_pkg_objs(prop_dictionary_t pkgd, - const char *pkgname, - const char *version, - const char *pkgver) +set_pkg_objs(prop_dictionary_t pkgd, const char *name, const char *version) { - if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", pkgname)) + char *pkgver; + + if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", name)) return EINVAL; - if (version != NULL) - if (!prop_dictionary_set_cstring_nocopy(pkgd, - "version", version)) - return EINVAL; - if (pkgver != NULL) - if (!prop_dictionary_set_cstring_nocopy(pkgd, - "pkgver", pkgver)) - return EINVAL; + if (!prop_dictionary_set_cstring_nocopy(pkgd, "version", version)) + return EINVAL; + + pkgver = xbps_xasprintf("%s-%s", name, version); + assert(pkgver != NULL); + + if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgver", pkgver)) { + free(pkgver); + return EINVAL; + } + free(pkgver); return 0; } @@ -156,7 +158,6 @@ set_pkg_objs(prop_dictionary_t pkgd, int xbps_set_pkg_state_installed(const char *pkgname, const char *version, - const char *pkgver, pkg_state_t state) { struct xbps_handle *xhp; @@ -178,7 +179,7 @@ xbps_set_pkg_state_installed(const char *pkgname, xhp->pkgdb = NULL; return ENOMEM; } - if ((rv = set_pkg_objs(pkgd, pkgname, version, pkgver)) != 0) { + if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0) { prop_object_release(xhp->pkgdb); prop_object_release(pkgd); xhp->pkgdb = NULL; @@ -201,8 +202,8 @@ xbps_set_pkg_state_installed(const char *pkgname, if (pkgd == NULL) { newpkg = true; pkgd = prop_dictionary_create(); - if ((rv = set_pkg_objs(pkgd, pkgname, - version, pkgver)) != 0) { + rv = set_pkg_objs(pkgd, pkgname, version); + if (rv != 0) { prop_object_release(pkgd); return rv; } diff --git a/lib/package_unpack.c b/lib/package_unpack.c index 313c45dd..203ce16f 100644 --- a/lib/package_unpack.c +++ b/lib/package_unpack.c @@ -625,7 +625,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) /* * Set package state to half-unpacked. */ - if ((rv = xbps_set_pkg_state_installed(pkgname, version, pkgver, + if ((rv = xbps_set_pkg_state_installed(pkgname, version, XBPS_PKG_STATE_HALF_UNPACKED)) != 0) { xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, rv, pkgname, version, @@ -647,7 +647,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod) /* * Set package state to unpacked. */ - if ((rv = xbps_set_pkg_state_installed(pkgname, version, pkgver, + if ((rv = xbps_set_pkg_state_installed(pkgname, version, XBPS_PKG_STATE_UNPACKED)) != 0) { xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, rv, pkgname, version,