libxbps: API/ABI break changes to fix issues with virtual packages.

Please see the NEWS file for info about this commit.
This commit is contained in:
Juan RP
2011-07-15 18:22:58 +02:00
parent fddb472dd0
commit 33d6d2e166
11 changed files with 198 additions and 153 deletions

View File

@@ -111,7 +111,7 @@ find_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
for (i = 0; i < prop_array_count(od->orphans_user); i++) {
prop_array_get_cstring_nocopy(od->orphans_user,
i, &curpkgname);
if (xbps_find_pkgname_in_array(reqby, curpkgname)) {
if (xbps_match_pkgname_in_array(reqby, curpkgname)) {
prop_array_add(od->array, obj);
return 0;
}

View File

@@ -44,7 +44,7 @@ add_pkg_into_reqby(prop_dictionary_t pkgd, const char *pkgver)
return ENOMEM;
}
if (xbps_find_string_in_array(reqby, pkgver)) {
if (xbps_match_string_in_array(reqby, pkgver)) {
if (alloc)
prop_object_release(reqby);
@@ -92,7 +92,7 @@ remove_pkg_from_reqby(prop_object_t obj, void *arg, bool *loop_done)
if (reqby == NULL || prop_array_count(reqby) == 0)
return 0;
if (xbps_find_pkgname_in_array(reqby, pkgname))
if (xbps_match_pkgname_in_array(reqby, pkgname))
if (!xbps_remove_pkgname_from_array(reqby, pkgname))
return EINVAL;

View File

@@ -39,73 +39,28 @@
* These functions manipulate plist files and objects shared by almost
* all library functions.
*/
static prop_dictionary_t
find_pkg_dict_from_plist(const char *plist,
const char *key,
const char *str,
bool bypattern)
{
prop_dictionary_t dict, obj, res;
assert(plist != NULL);
assert(str != NULL);
dict = prop_dictionary_internalize_from_zfile(plist);
if (dict == NULL) {
xbps_dbg_printf("cannot internalize %s for pkg %s: %s",
plist, str, strerror(errno));
return NULL;
}
if (bypattern)
obj = xbps_find_pkg_in_dict_by_pattern(dict, key, str);
else
obj = xbps_find_pkg_in_dict_by_name(dict, key, str);
if (obj == NULL) {
prop_object_release(dict);
return NULL;
}
res = prop_dictionary_copy(obj);
prop_object_release(dict);
return res;
}
prop_dictionary_t
xbps_find_pkg_dict_from_plist_by_name(const char *plist,
const char *key,
const char *pkgname)
{
return find_pkg_dict_from_plist(plist, key, pkgname, false);
}
prop_dictionary_t
xbps_find_pkg_dict_from_plist_by_pattern(const char *plist,
const char *key,
const char *pattern)
{
return find_pkg_dict_from_plist(plist, key, pattern, true);
}
bool
xbps_find_virtual_pkg_in_dict(prop_dictionary_t d,
const char *str,
bool bypattern)
xbps_match_virtual_pkg_in_dict(prop_dictionary_t d,
const char *str,
bool bypattern)
{
prop_array_t provides;
bool found = false;
if ((provides = prop_dictionary_get(d, "provides"))) {
if (bypattern)
found = xbps_find_pkgpattern_in_array(provides, str);
found = xbps_match_pkgpattern_in_array(provides, str);
else
found = xbps_find_pkgname_in_array(provides, str);
found = xbps_match_pkgname_in_array(provides, str);
}
return found;
}
static prop_dictionary_t
find_pkg_in_array(prop_array_t array, const char *str, bool bypattern)
find_pkg_in_array(prop_array_t array,
const char *str,
bool bypattern,
bool virtual)
{
prop_object_iterator_t iter;
prop_object_t obj = NULL;
@@ -136,11 +91,13 @@ find_pkg_in_array(prop_array_t array, const char *str, bool bypattern)
if (strcmp(dpkgn, str) == 0)
break;
}
if (!virtual)
continue;
/*
* Finally check if package pattern matches
* any virtual package version in dictionary.
*/
if (xbps_find_virtual_pkg_in_dict(obj, str, bypattern))
if (xbps_match_virtual_pkg_in_dict(obj, str, bypattern))
break;
}
prop_object_iterator_release(iter);
@@ -148,19 +105,20 @@ find_pkg_in_array(prop_array_t array, const char *str, bool bypattern)
errno = ENOENT;
return NULL;
}
return obj;
}
prop_dictionary_t
xbps_find_pkg_in_array_by_name(prop_array_t array, const char *name)
{
return find_pkg_in_array(array, name, false);
return find_pkg_in_array(array, name, false, false);
}
prop_dictionary_t
xbps_find_pkg_in_array_by_pattern(prop_array_t array, const char *pattern)
{
return find_pkg_in_array(array, pattern, true);
return find_pkg_in_array(array, pattern, true, false);
}
static const char *
@@ -250,9 +208,11 @@ find_pkg_in_dict(prop_dictionary_t d,
const char *key,
const char *str,
bool bypattern,
bool virtual)
bool virtual,
bool virtual_in_conf)
{
prop_array_t array;
prop_dictionary_t vpkgd;
assert(d != NULL);
assert(str != NULL);
@@ -262,10 +222,13 @@ find_pkg_in_dict(prop_dictionary_t d,
if (prop_object_type(array) != PROP_TYPE_ARRAY)
return NULL;
if (virtual)
return find_virtualpkg_user_in_array(array, str, bypattern);
if (virtual_in_conf) {
vpkgd = find_virtualpkg_user_in_array(array, str, bypattern);
if (vpkgd != NULL)
return vpkgd;
}
return find_pkg_in_array(array, str, bypattern);
return find_pkg_in_array(array, str, bypattern, virtual);
}
prop_dictionary_t
@@ -273,7 +236,7 @@ xbps_find_pkg_in_dict_by_name(prop_dictionary_t d,
const char *key,
const char *pkgname)
{
return find_pkg_in_dict(d, key, pkgname, false, false);
return find_pkg_in_dict(d, key, pkgname, false, false, false);
}
prop_dictionary_t
@@ -281,27 +244,87 @@ xbps_find_pkg_in_dict_by_pattern(prop_dictionary_t d,
const char *key,
const char *pattern)
{
return find_pkg_in_dict(d, key, pattern, true, false);
return find_pkg_in_dict(d, key, pattern, true, false, false);
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_user_in_dict_by_name(prop_dictionary_t d,
xbps_find_virtualpkg_in_dict_by_name(prop_dictionary_t d,
const char *key,
const char *name)
{
return find_pkg_in_dict(d, key, name, false, true);
return find_pkg_in_dict(d, key, name, false, true, false);
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_user_in_dict_by_pattern(prop_dictionary_t d,
xbps_find_virtualpkg_in_dict_by_pattern(prop_dictionary_t d,
const char *key,
const char *pattern)
{
return find_pkg_in_dict(d, key, pattern, true, true);
return find_pkg_in_dict(d, key, pattern, true, true, false);
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_dict_by_name(prop_dictionary_t d,
const char *key,
const char *name)
{
return find_pkg_in_dict(d, key, name, false, false, true);
}
prop_dictionary_t HIDDEN
xbps_find_virtualpkg_conf_in_dict_by_pattern(prop_dictionary_t d,
const char *key,
const char *pattern)
{
return find_pkg_in_dict(d, key, pattern, true, false, true);
}
static prop_dictionary_t
find_pkg_dict_from_plist(const char *plist,
const char *key,
const char *str,
bool bypattern)
{
prop_dictionary_t dict, obj, res;
assert(plist != NULL);
assert(str != NULL);
dict = prop_dictionary_internalize_from_zfile(plist);
if (dict == NULL) {
xbps_dbg_printf("cannot internalize %s for pkg %s: %s",
plist, str, strerror(errno));
return NULL;
}
obj = find_pkg_in_dict(dict, key, str, bypattern, true, true);
if (obj == NULL) {
prop_object_release(dict);
return NULL;
}
res = prop_dictionary_copy(obj);
prop_object_release(dict);
return res;
}
prop_dictionary_t
xbps_find_pkg_dict_installed(const char *str, bool bypattern)
xbps_find_pkg_dict_from_plist_by_name(const char *plist,
const char *key,
const char *pkgname)
{
return find_pkg_dict_from_plist(plist, key, pkgname, false);
}
prop_dictionary_t
xbps_find_pkg_dict_from_plist_by_pattern(const char *plist,
const char *key,
const char *pattern)
{
return find_pkg_dict_from_plist(plist, key, pattern, true);
}
static prop_dictionary_t
find_pkgd_installed(const char *str, bool bypattern, bool virtual)
{
const struct xbps_handle *xhp;
prop_dictionary_t pkgd, rpkgd = NULL;
@@ -314,7 +337,7 @@ xbps_find_pkg_dict_installed(const char *str, bool bypattern)
return NULL;
pkgd = find_pkg_in_dict(xhp->regpkgdb_dictionary,
"packages", str, bypattern, false);
"packages", str, bypattern, virtual, true);
if (pkgd == NULL)
return rpkgd;
@@ -338,8 +361,20 @@ xbps_find_pkg_dict_installed(const char *str, bool bypattern)
return rpkgd;
}
prop_dictionary_t
xbps_find_pkg_dict_installed(const char *str, bool bypattern)
{
return find_pkgd_installed(str, bypattern, false);
}
prop_dictionary_t
xbps_find_virtualpkg_dict_installed(const char *str, bool bypattern)
{
return find_pkgd_installed(str, bypattern, true);
}
static bool
find_string_in_array(prop_array_t array, const char *str, int mode)
match_string_in_array(prop_array_t array, const char *str, int mode)
{
prop_object_iterator_t iter;
prop_object_t obj;
@@ -389,19 +424,19 @@ find_string_in_array(prop_array_t array, const char *str, int mode)
}
bool
xbps_find_string_in_array(prop_array_t array, const char *str)
xbps_match_string_in_array(prop_array_t array, const char *str)
{
return find_string_in_array(array, str, 0);
return match_string_in_array(array, str, 0);
}
bool
xbps_find_pkgname_in_array(prop_array_t array, const char *pkgname)
xbps_match_pkgname_in_array(prop_array_t array, const char *pkgname)
{
return find_string_in_array(array, pkgname, 1);
return match_string_in_array(array, pkgname, 1);
}
bool
xbps_find_pkgpattern_in_array(prop_array_t array, const char *pattern)
xbps_match_pkgpattern_in_array(prop_array_t array, const char *pattern)
{
return find_string_in_array(array, pattern, 2);
return match_string_in_array(array, pattern, 2);
}

View File

@@ -326,8 +326,7 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
break;
}
free(pkgname);
if (xbps_find_virtual_pkg_in_dict(tmpd,
reqpkg, true)) {
if (xbps_match_virtual_pkg_in_dict(tmpd,reqpkg,true)) {
/*
* Check if required dependency is a virtual
* package and is satisfied by an

View File

@@ -285,11 +285,11 @@ repo_find_virtualpkg_cb(struct repository_pool_index *rpi, void *arg, bool *done
if (rpf->bypattern) {
rpf->pkgd =
xbps_find_virtualpkg_user_in_dict_by_pattern(rpi->rpi_repod,
xbps_find_virtualpkg_conf_in_dict_by_pattern(rpi->rpi_repod,
"packages", rpf->pattern);
} else {
rpf->pkgd =
xbps_find_virtualpkg_user_in_dict_by_name(rpi->rpi_repod,
xbps_find_virtualpkg_conf_in_dict_by_name(rpi->rpi_repod,
"packages", rpf->pattern);
}
if (rpf->pkgd) {
@@ -311,9 +311,19 @@ repo_find_pkg_cb(struct repository_pool_index *rpi, void *arg, bool *done)
if (rpf->bypattern) {
rpf->pkgd = xbps_find_pkg_in_dict_by_pattern(rpi->rpi_repod,
"packages", rpf->pattern);
/* If no pkg exists matching pattern, look for virtual packages */
if (rpf->pkgd == NULL) {
rpf->pkgd = xbps_find_virtualpkg_in_dict_by_pattern(
rpi->rpi_repod, "packages", rpf->pattern);
}
} else {
rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod,
"packages", rpf->pattern);
/* If no pkg exists matching pattern, look for virtual packages */
if (rpf->pkgd == NULL) {
rpf->pkgd = xbps_find_virtualpkg_in_dict_by_name(
rpi->rpi_repod, "packages", rpf->pattern);
}
}
if (rpf->pkgd) {
/*
@@ -336,9 +346,8 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
bool *done)
{
struct repo_pool_fpkg *rpf = arg;
prop_dictionary_t instpkgd, vpkgd;
prop_dictionary_t instpkgd;
const char *instver, *repover;
char *vpattern = NULL;
rpf->pkgd = xbps_find_pkg_in_dict_by_name(rpi->rpi_repod,
"packages", rpf->pattern);
@@ -369,42 +378,6 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
errno = EEXIST;
return 0;
}
/*
* New package version is greater than current installed, but first
* check if this is a virtual package and it's set specifically
* in the configuration file.
*/
vpattern = xbps_xasprintf("%s>=0", rpf->pattern);
if (vpattern == NULL)
return EINVAL;
vpkgd = xbps_find_virtualpkg_user_in_dict_by_pattern(
rpi->rpi_repod, "packages", vpattern);
if (vpkgd) {
/*
* Virtual package enabled in conf file and new
* version found.
*/
free(vpattern);
prop_dictionary_set_cstring(vpkgd, "repository",
rpi->rpi_uri);
*done = true;
errno = 0;
rpf->pkgfound = true;
return 0;
} else {
/*
* Virtual package not enabled in conf file but it's
* currently proviving the same virtual package that
* we are updating... ignore it.
*/
if (xbps_find_virtual_pkg_in_dict(rpf->pkgd,
vpattern, true)) {
free(vpattern);
return 0;
}
free(vpattern);
}
/*
* New package version found, exit from the loop.
*/

View File

@@ -70,7 +70,7 @@ pkgdep_find(const char *name, const char *trans)
}
if (pd->d == NULL)
continue;
if (xbps_find_virtual_pkg_in_dict(pd->d, name, false))
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false))
return pd;
}
@@ -93,7 +93,7 @@ pkgdep_find_idx(const char *name, const char *trans)
}
if (pd->d == NULL)
continue;
if (xbps_find_virtual_pkg_in_dict(pd->d, name, false))
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false))
return idx;
idx++;
@@ -231,6 +231,10 @@ again:
}
curpkgd = xbps_find_pkg_in_dict_by_name(transd,
"unsorted_deps", pkgnamedep);
if (curpkgd == NULL) {
curpkgd = xbps_find_virtualpkg_in_dict_by_name(transd,
"unsorted_deps", pkgnamedep);
}
if (curpkgd == NULL) {
free(pkgnamedep);
rv = EINVAL;

View File

@@ -199,7 +199,8 @@ xbps_check_is_installed_pkg_by_pattern(const char *pattern)
assert(pattern != NULL);
dict = xbps_find_pkg_dict_installed(pattern, true);
if ((dict = xbps_find_pkg_dict_installed(pattern, true)) == NULL)
dict = xbps_find_virtualpkg_dict_installed(pattern, true);
if (dict == NULL) {
if (errno == ENOENT) {
errno = 0;