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:
parent
341ab01219
commit
ef6d1adf91
@ -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 */
|
||||
|
@ -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);
|
||||
|
||||
/**
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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))
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "version", version))
|
||||
return EINVAL;
|
||||
if (pkgver != NULL)
|
||||
if (!prop_dictionary_set_cstring_nocopy(pkgd,
|
||||
"pkgver", pkgver))
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user