libxbps: fix for vpkg providers in multiple repos.

Added new test case by @st3r4g via #206

Closes #206
This commit is contained in:
Juan RP 2020-01-18 12:50:59 +01:00
parent 5ff3ab5c60
commit ef9260a16e
No known key found for this signature in database
GPG Key ID: AF19F6CB482F9368
5 changed files with 45 additions and 12 deletions

View File

@ -59,7 +59,7 @@ store_vars(struct xbps_handle *xhp, xbps_dictionary_t *d,
if (*d == NULL) if (*d == NULL)
*d = xbps_dictionary_create(); *d = xbps_dictionary_create();
if (xhp->vpkgd_conf) if (xhp->vpkgd_conf == NULL)
xhp->vpkgd_conf = xbps_dictionary_create(); xhp->vpkgd_conf = xbps_dictionary_create();
/* /*

View File

@ -304,7 +304,7 @@ xbps_find_virtualpkg_in_dict(struct xbps_handle *xhp,
xbps_dictionary_t pkgd = NULL; xbps_dictionary_t pkgd = NULL;
const char *vpkg; const char *vpkg;
/* Try matching vpkg from configuration files */ /* Try matching vpkg via xhp->vpkgd */
vpkg = vpkg_user_conf(xhp, pkg, false); vpkg = vpkg_user_conf(xhp, pkg, false);
if (vpkg != NULL) { if (vpkg != NULL) {
if (xbps_pkgpattern_version(vpkg)) if (xbps_pkgpattern_version(vpkg))

View File

@ -42,11 +42,15 @@
bool bool
xbps_match_virtual_pkg_in_array(xbps_array_t a, const char *str) xbps_match_virtual_pkg_in_array(xbps_array_t a, const char *str)
{ {
if ((xbps_match_pkgname_in_array(a, str)) || if (xbps_pkgpattern_version(str)) {
(xbps_match_pkgdep_in_array(a, str)) || if (xbps_match_pkgdep_in_array(a, str) ||
(xbps_match_pkgpattern_in_array(a, str))) xbps_match_pkgpattern_in_array(a, str))
return true; return true;
} else if (xbps_pkg_version(str)) {
return xbps_match_string_in_array(a, str);
} else {
return xbps_match_pkgname_in_array(a, str);
}
return false; return false;
} }

View File

@ -398,8 +398,7 @@ xbps_repo_get_virtualpkg(struct xbps_repo *repo, const char *pkg)
pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg); pkgd = xbps_find_virtualpkg_in_dict(repo->xhp, repo->idx, pkg);
if (pkgd) { if (pkgd) {
xbps_dictionary_set_cstring_nocopy(pkgd, xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
"repository", repo->uri);
return pkgd; return pkgd;
} }
return NULL; return NULL;
@ -417,14 +416,14 @@ xbps_repo_get_pkg(struct xbps_repo *repo, const char *pkg)
return NULL; return NULL;
/* Try matching vpkg from configuration files */ /* Try matching vpkg from configuration files */
if ((pkgd = xbps_find_virtualpkg_in_conf(repo->xhp, repo->idx, pkg))) if ((pkgd = xbps_find_virtualpkg_in_conf(repo->xhp, repo->idx, pkg))) {
xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
return pkgd; return pkgd;
}
/* ... otherwise match a real pkg */ /* ... otherwise match a real pkg */
pkgd = xbps_find_pkg_in_dict(repo->idx, pkg); pkgd = xbps_find_pkg_in_dict(repo->idx, pkg);
if (pkgd) { if (pkgd) {
xbps_dictionary_set_cstring_nocopy(pkgd, xbps_dictionary_set_cstring_nocopy(pkgd, "repository", repo->uri);
"repository", repo->uri);
return pkgd; return pkgd;
} }

View File

@ -334,6 +334,35 @@ vpkg_provider_remove_body() {
atf_check_equal $? 19 atf_check_equal $? 19
} }
atf_test_case vpkg_multirepo
vpkg_multirepo_head() {
atf_set "descr" "Tests for virtual pkgs: vpkg provider in multiple repos"
}
vpkg_multirepo_body() {
mkdir empty repo-1 repo-2
cd repo-1
xbps-create -n A-1.0_1 -s A -A noarch -P V-0_1 ../empty
atf_check_equal $? 0
cd ../repo-2
xbps-create -n B-1.0_1 -s B -A noarch -P V-0_1 ../empty
atf_check_equal $? 0
cd ..
xbps-rindex -a repo-1/*.xbps
atf_check_equal $? 0
xbps-rindex -a repo-2/*.xbps
atf_check_equal $? 0
echo "virtualpkg=V-0_1:B" > virtualpkg.conf
out="$(xbps-install -C $PWD -r root --repo=repo-1 --repo=repo-2 -n V|awk '{print $1}')"
atf_check_equal "$out" "B-1.0_1"
}
atf_init_test_cases() { atf_init_test_cases() {
atf_add_test_case vpkg_dont_update atf_add_test_case vpkg_dont_update
atf_add_test_case vpkg_replace_provider atf_add_test_case vpkg_replace_provider
@ -344,4 +373,5 @@ atf_init_test_cases() {
atf_add_test_case vpkg_incompat_downgrade atf_add_test_case vpkg_incompat_downgrade
atf_add_test_case vpkg_provider_and_revdeps_downgrade atf_add_test_case vpkg_provider_and_revdeps_downgrade
atf_add_test_case vpkg_provider_remove atf_add_test_case vpkg_provider_remove
atf_add_test_case vpkg_multirepo
} }