xbps_set_pkg_state_installed: simplify (API change).

The third optional argument "pkgver" clearly is useless because we can
create it internally with "pkgname" and "version" arguments instead.

Also make the "version" argument mandatory.
This commit is contained in:
Juan RP 2012-04-10 09:43:59 +02:00
parent 341ab01219
commit ef6d1adf91
6 changed files with 27 additions and 35 deletions

View File

@ -117,7 +117,7 @@ main(int argc, char **argv)
struct xbps_handle xh; struct xbps_handle xh;
struct xferstat xfer; struct xferstat xfer;
const char *pkgn, *version, *rootdir = NULL, *confdir = NULL; 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; bool in_chroot = false;
int flags = 0, i, c, rv = 0; 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, "pkgname", argv[1]);
prop_dictionary_set_cstring_nocopy(dict, "version", argv[2]); prop_dictionary_set_cstring_nocopy(dict, "version", argv[2]);
prop_dictionary_set_cstring_nocopy(dict, "short_desc", argv[3]); 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); prop_dictionary_set_bool(dict, "automatic-install", false);
pkgd = xbps_pkgdb_get_pkgd(argv[1], false); pkgd = xbps_pkgdb_get_pkgd(argv[1], false);
@ -207,7 +201,7 @@ main(int argc, char **argv)
pkgn, version, MSG_RESET); pkgn, version, MSG_RESET);
} else { } else {
rv = xbps_set_pkg_state_installed(argv[1], argv[2], rv = xbps_set_pkg_state_installed(argv[1], argv[2],
pkgver, XBPS_PKG_STATE_INSTALLED); XBPS_PKG_STATE_INSTALLED);
if (rv != 0) if (rv != 0)
goto out; goto out;
@ -223,7 +217,6 @@ main(int argc, char **argv)
argv[1], argv[2], MSG_RESET); argv[1], argv[2], MSG_RESET);
} }
} }
free(pkgver);
prop_object_release(dict); prop_object_release(dict);
} else if (strcasecmp(argv[0], "unregister") == 0) { } else if (strcasecmp(argv[0], "unregister") == 0) {
/* Unregisters a package from the database */ /* Unregisters a package from the database */

View File

@ -56,8 +56,8 @@
*/ */
#define XBPS_PKGINDEX_VERSION "1.4" #define XBPS_PKGINDEX_VERSION "1.4"
#define XBPS_API_VERSION "20120405" #define XBPS_API_VERSION "20120410"
#define XBPS_VERSION "0.15" #define XBPS_VERSION "0.16"
/** /**
* @def XBPS_RELVER * @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. * Sets package state \a state in package \a pkgname.
* *
* @param[in] pkgname Package name. * @param[in] pkgname Package name.
* @param[in] version Package version (optional). * @param[in] version Package version.
* @param[in] pkgver Package name/version (optional).
* @param[in] state Package state to be set. * @param[in] state Package state to be set.
* *
* @return 0 on success, otherwise an errno value. * @return 0 on success, otherwise an errno value.
*/ */
int xbps_set_pkg_state_installed(const char *pkgname, int xbps_set_pkg_state_installed(const char *pkgname,
const char *version, const char *version,
const char *pkgver,
pkg_state_t state); pkg_state_t state);
/** /**

View File

@ -163,7 +163,7 @@ xbps_configure_pkg(const char *pkgname,
} }
} }
free(buf); free(buf);
rv = xbps_set_pkg_state_installed(pkgname, lver, pkgver, rv = xbps_set_pkg_state_installed(pkgname, lver,
XBPS_PKG_STATE_INSTALLED); XBPS_PKG_STATE_INSTALLED);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv, xbps_set_cb_state(XBPS_STATE_CONFIGURE_FAIL, rv,

View File

@ -375,7 +375,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
/* /*
* Set package state to "half-removed". * 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); XBPS_PKG_STATE_HALF_REMOVED);
if (rv != 0) { if (rv != 0) {
xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL, xbps_set_cb_state(XBPS_STATE_REMOVE_FAIL,

View File

@ -133,22 +133,24 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
} }
static int static int
set_pkg_objs(prop_dictionary_t pkgd, set_pkg_objs(prop_dictionary_t pkgd, const char *name, const char *version)
const char *pkgname,
const char *version,
const char *pkgver)
{ {
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", pkgname)) char *pkgver;
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", name))
return EINVAL; return EINVAL;
if (version != NULL) if (!prop_dictionary_set_cstring_nocopy(pkgd, "version", version))
if (!prop_dictionary_set_cstring_nocopy(pkgd,
"version", version))
return EINVAL; return EINVAL;
if (pkgver != NULL)
if (!prop_dictionary_set_cstring_nocopy(pkgd, pkgver = xbps_xasprintf("%s-%s", name, version);
"pkgver", pkgver)) assert(pkgver != NULL);
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgver", pkgver)) {
free(pkgver);
return EINVAL; return EINVAL;
}
free(pkgver);
return 0; return 0;
} }
@ -156,7 +158,6 @@ set_pkg_objs(prop_dictionary_t pkgd,
int int
xbps_set_pkg_state_installed(const char *pkgname, xbps_set_pkg_state_installed(const char *pkgname,
const char *version, const char *version,
const char *pkgver,
pkg_state_t state) pkg_state_t state)
{ {
struct xbps_handle *xhp; struct xbps_handle *xhp;
@ -178,7 +179,7 @@ xbps_set_pkg_state_installed(const char *pkgname,
xhp->pkgdb = NULL; xhp->pkgdb = NULL;
return ENOMEM; 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(xhp->pkgdb);
prop_object_release(pkgd); prop_object_release(pkgd);
xhp->pkgdb = NULL; xhp->pkgdb = NULL;
@ -201,8 +202,8 @@ xbps_set_pkg_state_installed(const char *pkgname,
if (pkgd == NULL) { if (pkgd == NULL) {
newpkg = true; newpkg = true;
pkgd = prop_dictionary_create(); pkgd = prop_dictionary_create();
if ((rv = set_pkg_objs(pkgd, pkgname, rv = set_pkg_objs(pkgd, pkgname, version);
version, pkgver)) != 0) { if (rv != 0) {
prop_object_release(pkgd); prop_object_release(pkgd);
return rv; return rv;
} }

View File

@ -625,7 +625,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Set package state to half-unpacked. * 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_PKG_STATE_HALF_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,
@ -647,7 +647,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
/* /*
* Set package state to unpacked. * 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_PKG_STATE_UNPACKED)) != 0) {
xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL, xbps_set_cb_state(XBPS_STATE_UNPACK_FAIL,
rv, pkgname, version, rv, pkgname, version,