xbps_set_pkg_state_installed: added two new optional arguments: version and pkgver.
This can be used to avoid some rare cases where the pkg dictionary is regpkgdb is in a state where code can be faulty if those objects are not found.
This commit is contained in:
parent
9abcb92e39
commit
a306cebc96
@ -178,7 +178,7 @@ main(int argc, char **argv)
|
|||||||
prop_dictionary_set_cstring(dict, "pkgver", pkgver);
|
prop_dictionary_set_cstring(dict, "pkgver", pkgver);
|
||||||
free(pkgver);
|
free(pkgver);
|
||||||
|
|
||||||
rv = xbps_set_pkg_state_installed(argv[1],
|
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)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
* @def XBPS_RELVER
|
* @def XBPS_RELVER
|
||||||
* Current library release date.
|
* Current library release date.
|
||||||
*/
|
*/
|
||||||
#define XBPS_RELVER "20110221"
|
#define XBPS_RELVER "20110222"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @def XBPS_META_PATH
|
* @def XBPS_META_PATH
|
||||||
@ -1130,11 +1130,16 @@ int xbps_get_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] pkgver Package name/version touple (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, pkg_state_t state);
|
int xbps_set_pkg_state_installed(const char *pkgname,
|
||||||
|
const char *version,
|
||||||
|
const char *pkgver,
|
||||||
|
pkg_state_t state);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets package state \a state in package dictionary \a dict.
|
* Sets package state \a state in package dictionary \a dict.
|
||||||
|
@ -89,7 +89,7 @@ xbps_configure_pkg(const char *pkgname,
|
|||||||
const struct xbps_handle *xhp;
|
const struct xbps_handle *xhp;
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
const char *lver;
|
const char *lver;
|
||||||
char *buf;
|
char *buf, *pkgver;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
pkg_state_t state = 0;
|
pkg_state_t state = 0;
|
||||||
bool reconfigure = false;
|
bool reconfigure = false;
|
||||||
@ -147,6 +147,13 @@ xbps_configure_pkg(const char *pkgname,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
pkgver = xbps_xasprintf("%s-%s", pkgname, lver);
|
||||||
|
if (pkgver == NULL)
|
||||||
|
return ENOMEM;
|
||||||
|
|
||||||
return xbps_set_pkg_state_installed(pkgname, XBPS_PKG_STATE_INSTALLED);
|
rv = xbps_set_pkg_state_installed(pkgname, lver, pkgver,
|
||||||
|
XBPS_PKG_STATE_INSTALLED);
|
||||||
|
free(pkgver);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -174,6 +174,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
|||||||
{
|
{
|
||||||
const struct xbps_handle *xhp;
|
const struct xbps_handle *xhp;
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
|
const char *pkgver;
|
||||||
char *buf;
|
char *buf;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
bool rmfile_exists = false;
|
bool rmfile_exists = false;
|
||||||
@ -235,6 +236,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
|||||||
free(buf);
|
free(buf);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
prop_dictionary_get_cstring_nocopy(dict, "pkgver", &pkgver);
|
||||||
|
|
||||||
/* Remove links */
|
/* Remove links */
|
||||||
if ((rv = xbps_remove_pkg_files(dict, "links")) != 0) {
|
if ((rv = xbps_remove_pkg_files(dict, "links")) != 0) {
|
||||||
@ -278,7 +280,7 @@ xbps_remove_pkg(const char *pkgname, const char *version, bool update)
|
|||||||
/*
|
/*
|
||||||
* Set package state to "config-files".
|
* Set package state to "config-files".
|
||||||
*/
|
*/
|
||||||
rv = xbps_set_pkg_state_installed(pkgname,
|
rv = xbps_set_pkg_state_installed(pkgname, version, pkgver,
|
||||||
XBPS_PKG_STATE_CONFIG_FILES);
|
XBPS_PKG_STATE_CONFIG_FILES);
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,8 +138,32 @@ xbps_set_pkg_state_dictionary(prop_dictionary_t dict, pkg_state_t state)
|
|||||||
return set_new_state(dict, state);
|
return set_new_state(dict, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
set_pkg_objs(prop_dictionary_t pkgd,
|
||||||
|
const char *pkgname,
|
||||||
|
const char *version,
|
||||||
|
const char *pkgver)
|
||||||
|
{
|
||||||
|
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname", pkgname))
|
||||||
|
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;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
|
xbps_set_pkg_state_installed(const char *pkgname,
|
||||||
|
const char *version,
|
||||||
|
const char *pkgver,
|
||||||
|
pkg_state_t state)
|
||||||
{
|
{
|
||||||
const struct xbps_handle *xhp;
|
const struct xbps_handle *xhp;
|
||||||
prop_dictionary_t dict = NULL, pkgd;
|
prop_dictionary_t dict = NULL, pkgd;
|
||||||
@ -173,10 +197,7 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
|
|||||||
prop_object_release(array);
|
prop_object_release(array);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
if ((rv = set_pkg_objs(pkgd, pkgname, version, pkgver)) != 0) {
|
||||||
if (!prop_dictionary_set_cstring_nocopy(pkgd, "pkgname",
|
|
||||||
pkgname)) {
|
|
||||||
rv = EINVAL;
|
|
||||||
prop_object_release(array);
|
prop_object_release(array);
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
goto out;
|
goto out;
|
||||||
@ -209,9 +230,8 @@ xbps_set_pkg_state_installed(const char *pkgname, pkg_state_t state)
|
|||||||
|
|
||||||
newpkg = true;
|
newpkg = true;
|
||||||
pkgd = prop_dictionary_create();
|
pkgd = prop_dictionary_create();
|
||||||
if (!prop_dictionary_set_cstring_nocopy(pkgd,
|
if ((rv = set_pkg_objs(pkgd, pkgname,
|
||||||
"pkgname", pkgname)) {
|
version, pkgver)) != 0) {
|
||||||
rv = EINVAL;
|
|
||||||
prop_object_release(pkgd);
|
prop_object_release(pkgd);
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
@ -463,7 +463,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
|||||||
{
|
{
|
||||||
const struct xbps_handle *xhp;
|
const struct xbps_handle *xhp;
|
||||||
struct archive *ar;
|
struct archive *ar;
|
||||||
const char *pkgname, *version, *repoloc;
|
const char *pkgname, *version, *repoloc, *pkgver;
|
||||||
char *bpkg;
|
char *bpkg;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
@ -471,6 +471,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
|||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgname", &pkgname);
|
||||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "version", &version);
|
||||||
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "pkgver", &pkgver);
|
||||||
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
prop_dictionary_get_cstring_nocopy(pkg_repod, "repository", &repoloc);
|
||||||
|
|
||||||
bpkg = xbps_get_binpkg_repo_uri(pkg_repod, repoloc);
|
bpkg = xbps_get_binpkg_repo_uri(pkg_repod, repoloc);
|
||||||
@ -514,11 +515,11 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg_repod)
|
|||||||
bpkg, strerror(rv));
|
bpkg, strerror(rv));
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set package state to unpacked.
|
* Set package state to unpacked.
|
||||||
*/
|
*/
|
||||||
rv = xbps_set_pkg_state_installed(pkgname, XBPS_PKG_STATE_UNPACKED);
|
rv = xbps_set_pkg_state_installed(pkgname, version, pkgver,
|
||||||
|
XBPS_PKG_STATE_UNPACKED);
|
||||||
if (rv != 0) {
|
if (rv != 0) {
|
||||||
xbps_error_printf("failed to set `%s-%s' to unpacked "
|
xbps_error_printf("failed to set `%s-%s' to unpacked "
|
||||||
"state: %s\n", pkgname, version, strerror(rv));
|
"state: %s\n", pkgname, version, strerror(rv));
|
||||||
|
Loading…
Reference in New Issue
Block a user