libxbps: require an underscore in strings to detect correctly pkgname/version.
This commit is contained in:
@@ -71,7 +71,6 @@ find_pkg_in_array(prop_array_t array,
|
||||
*/
|
||||
if (xbps_match_virtual_pkg_in_dict(obj, str, bypattern))
|
||||
break;
|
||||
|
||||
} else if (bypattern) {
|
||||
/*
|
||||
* Check if package pattern matches the
|
||||
@@ -166,7 +165,7 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
|
||||
{
|
||||
const struct xbps_handle *xhp;
|
||||
const char *vpkgver, *pkg = NULL;
|
||||
char *vpkgname = NULL;
|
||||
char *vpkgname = NULL, *tmp;
|
||||
size_t i, j, cnt;
|
||||
|
||||
xhp = xbps_handle_get();
|
||||
@@ -181,8 +180,16 @@ find_virtualpkg_user_in_conf(const char *vpkg, bool bypattern)
|
||||
for (i = 0; i < cnt; i++) {
|
||||
cfg_t *sec = cfg_getnsec(xhp->cfg, "virtual-package", i);
|
||||
for (j = 0; j < cfg_size(sec, "targets"); j++) {
|
||||
tmp = NULL;
|
||||
vpkgver = cfg_getnstr(sec, "targets", j);
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
if (strchr(vpkgver, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", vpkgver);
|
||||
assert(tmp != NULL);
|
||||
vpkgname = xbps_pkg_name(tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
vpkgname = xbps_pkg_name(vpkgver);
|
||||
}
|
||||
if (vpkgname == NULL)
|
||||
break;
|
||||
if (bypattern) {
|
||||
|
||||
@@ -63,15 +63,27 @@ xbps_match_any_virtualpkg_in_rundeps(prop_array_t rundeps,
|
||||
prop_array_t provides)
|
||||
{
|
||||
const char *vpkgver, *pkgpattern;
|
||||
char *tmp;
|
||||
size_t i, x;
|
||||
|
||||
for (i = 0; i < prop_array_count(provides); i++) {
|
||||
tmp = NULL;
|
||||
prop_array_get_cstring_nocopy(provides, i, &vpkgver);
|
||||
if (strchr(vpkgver, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", vpkgver);
|
||||
assert(tmp != NULL);
|
||||
vpkgver = tmp;
|
||||
}
|
||||
for (x = 0; x < prop_array_count(rundeps); x++) {
|
||||
prop_array_get_cstring_nocopy(rundeps, x, &pkgpattern);
|
||||
if (xbps_pkgpattern_match(vpkgver, pkgpattern))
|
||||
if (xbps_pkgpattern_match(vpkgver, pkgpattern)) {
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -82,7 +94,7 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
|
||||
prop_object_iterator_t iter;
|
||||
prop_object_t obj;
|
||||
const char *pkgdep;
|
||||
char *curpkgname;
|
||||
char *curpkgname, *tmp;
|
||||
bool found = false;
|
||||
|
||||
assert(prop_object_type(array) == PROP_TYPE_ARRAY);
|
||||
@@ -93,7 +105,7 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
|
||||
return false;
|
||||
|
||||
while ((obj = prop_object_iterator_next(iter))) {
|
||||
assert(prop_object_type(obj) == PROP_TYPE_STRING);
|
||||
tmp = NULL;
|
||||
if (mode == 0) {
|
||||
/* match by string */
|
||||
if (prop_string_equals_cstring(obj, str)) {
|
||||
@@ -103,7 +115,14 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
|
||||
} else if (mode == 1) {
|
||||
/* match by pkgname */
|
||||
pkgdep = prop_string_cstring_nocopy(obj);
|
||||
curpkgname = xbps_pkg_name(pkgdep);
|
||||
if (strchr(pkgdep, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", pkgdep);
|
||||
assert(tmp != NULL);
|
||||
curpkgname = xbps_pkg_name(tmp);
|
||||
free(tmp);
|
||||
} else {
|
||||
curpkgname = xbps_pkg_name(pkgdep);
|
||||
}
|
||||
if (curpkgname == NULL)
|
||||
break;
|
||||
if (strcmp(curpkgname, str) == 0) {
|
||||
@@ -115,17 +134,36 @@ match_string_in_array(prop_array_t array, const char *str, int mode)
|
||||
} else if (mode == 2) {
|
||||
/* match pkgpattern against pkgdep */
|
||||
pkgdep = prop_string_cstring_nocopy(obj);
|
||||
if (strchr(pkgdep, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", pkgdep);
|
||||
assert(tmp != NULL);
|
||||
pkgdep = tmp;
|
||||
}
|
||||
if (xbps_pkgpattern_match(pkgdep, str)) {
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
|
||||
} else if (mode == 3) {
|
||||
/* match pkgdep against pkgpattern */
|
||||
pkgdep = prop_string_cstring_nocopy(obj);
|
||||
if (strchr(pkgdep, '_') == NULL) {
|
||||
tmp = xbps_xasprintf("%s_1", pkgdep);
|
||||
assert(tmp != NULL);
|
||||
pkgdep = tmp;
|
||||
}
|
||||
if (xbps_pkgpattern_match(str, pkgdep)) {
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (tmp != NULL)
|
||||
free(tmp);
|
||||
}
|
||||
}
|
||||
prop_object_iterator_release(iter);
|
||||
|
||||
@@ -241,8 +241,6 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
|
||||
{
|
||||
prop_dictionary_t pkgd;
|
||||
pkg_state_t state;
|
||||
size_t len, i;
|
||||
char *pkgname, *pkgstr = NULL;
|
||||
bool bypattern, best, exact;
|
||||
int rv;
|
||||
|
||||
@@ -250,7 +248,7 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
|
||||
bypattern = true;
|
||||
best = false;
|
||||
exact = false;
|
||||
} else if (strchr(pkg, '=')) {
|
||||
} else if (xbps_pkg_name(pkg)) {
|
||||
exact = true;
|
||||
bypattern = false;
|
||||
best = false;
|
||||
@@ -260,29 +258,7 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
|
||||
best = true;
|
||||
}
|
||||
|
||||
if (exact) {
|
||||
/* find out pkgname */
|
||||
pkgname = strdup(pkg);
|
||||
assert(pkgname != NULL);
|
||||
len = strcspn(pkg, "=");
|
||||
for (i = 0; i < len; i++)
|
||||
pkgname[i] = pkg[i];
|
||||
pkgname[i] = '\0';
|
||||
pkgd = xbps_pkgdb_get_pkgd(pkgname, false);
|
||||
free(pkgname);
|
||||
/* replace equal with an hyphen */
|
||||
pkgstr = strdup(pkg);
|
||||
for (i = 0; i < strlen(pkgstr); i++) {
|
||||
if (pkgstr[i] == '=') {
|
||||
pkgstr[i] = '-';
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern);
|
||||
}
|
||||
|
||||
if (pkgd != NULL) {
|
||||
if ((pkgd = xbps_pkgdb_get_pkgd(pkg, bypattern)) != NULL) {
|
||||
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
|
||||
prop_object_release(pkgd);
|
||||
return EINVAL;
|
||||
@@ -293,11 +269,7 @@ xbps_transaction_install_pkg(const char *pkg, bool reinstall)
|
||||
return EEXIST;
|
||||
}
|
||||
}
|
||||
rv = transaction_find_pkg(pkgstr ? pkgstr : pkg, bypattern,
|
||||
best, exact, TRANS_INSTALL);
|
||||
if (pkgstr != NULL)
|
||||
free(pkgstr);
|
||||
|
||||
rv = transaction_find_pkg(pkg, bypattern, best, exact, TRANS_INSTALL);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
69
lib/util.c
69
lib/util.c
@@ -102,67 +102,61 @@ xbps_check_is_installed_pkg_by_name(const char *pkgname)
|
||||
|
||||
assert(pkgname != NULL);
|
||||
|
||||
pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false);
|
||||
if (prop_object_type(pkgd) == PROP_TYPE_DICTIONARY) {
|
||||
prop_object_release(pkgd);
|
||||
return true;
|
||||
}
|
||||
if (((pkgd = xbps_find_pkg_dict_installed(pkgname, false)) == NULL) &&
|
||||
((pkgd = xbps_find_virtualpkg_dict_installed(pkgname, false)) == NULL))
|
||||
return false;
|
||||
|
||||
return false;
|
||||
prop_object_release(pkgd);
|
||||
return true;
|
||||
}
|
||||
|
||||
const char *
|
||||
xbps_pkg_version(const char *pkg)
|
||||
{
|
||||
const char *tmp;
|
||||
const char *p;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
/* Get the required version */
|
||||
tmp = strrchr(pkg, '-');
|
||||
if (tmp == NULL)
|
||||
if ((p = strrchr(pkg, '-')) == NULL)
|
||||
return NULL;
|
||||
|
||||
return tmp + 1; /* skip first '-' */
|
||||
if (strrchr(p, '_') == NULL)
|
||||
return NULL;
|
||||
|
||||
return p + 1; /* skip first '_' */
|
||||
}
|
||||
|
||||
const char *
|
||||
xbps_pkg_revision(const char *pkg)
|
||||
{
|
||||
const char *tmp;
|
||||
const char *p;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
/* Get the required revision */
|
||||
tmp = strrchr(pkg, '_');
|
||||
if (tmp == NULL)
|
||||
if ((p = strrchr(pkg, '_')) == NULL)
|
||||
return NULL;
|
||||
|
||||
return tmp + 1; /* skip first '_' */
|
||||
return p + 1; /* skip first '_' */
|
||||
}
|
||||
|
||||
char *
|
||||
xbps_pkg_name(const char *pkg)
|
||||
{
|
||||
const char *tmp;
|
||||
char *pkgname;
|
||||
size_t len = 0;
|
||||
const char *p;
|
||||
char *buf;
|
||||
size_t len;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
/* Get package name */
|
||||
tmp = strrchr(pkg, '-');
|
||||
if (tmp == NULL)
|
||||
if ((p = strrchr(pkg, '-')) == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(pkg) - strlen(tmp) + 1;
|
||||
pkgname = malloc(len);
|
||||
if (pkgname == NULL)
|
||||
if (strrchr(p, '_') == NULL)
|
||||
return NULL;
|
||||
|
||||
strlcpy(pkgname, pkg, len);
|
||||
len = strlen(pkg) - strlen(p) + 1;
|
||||
buf = malloc(len);
|
||||
assert(buf != NULL);
|
||||
strlcpy(buf, pkg, len);
|
||||
|
||||
return pkgname;
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -173,8 +167,7 @@ xbps_pkgpattern_name(const char *pkg)
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
res = strpbrk(pkg, "><*?[]");
|
||||
if (res == NULL)
|
||||
if ((res = strpbrk(pkg, "><*?[]")) == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(pkg) - strlen(res) + 1;
|
||||
@@ -182,9 +175,7 @@ xbps_pkgpattern_name(const char *pkg)
|
||||
len--;
|
||||
|
||||
pkgname = malloc(len);
|
||||
if (pkgname == NULL)
|
||||
return NULL;
|
||||
|
||||
assert(pkgname != NULL);
|
||||
strlcpy(pkgname, pkg, len);
|
||||
|
||||
return pkgname;
|
||||
@@ -193,15 +184,9 @@ xbps_pkgpattern_name(const char *pkg)
|
||||
const char *
|
||||
xbps_pkgpattern_version(const char *pkg)
|
||||
{
|
||||
char *res;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
res = strpbrk(pkg, "><*?[]");
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
|
||||
return res;
|
||||
return strpbrk(pkg, "><*?[]");
|
||||
}
|
||||
|
||||
static char *
|
||||
|
||||
Reference in New Issue
Block a user