libxbps: separate virtualpkg conf stuff from repository_pool_find_pkg.
Now to find a virtualpkg set by the user in conf file, there is a new function: xbps_repository_pool_find_virtualpkg(). Use it in some places to make jpeg -> libjpeg-turbo (and other pkgs that can be replaced with other virtual pkgs) work correctly even if installed multiple times.
This commit is contained in:
parent
104bec27e5
commit
12af2370da
@ -1229,7 +1229,8 @@ int xbps_repository_pool_foreach(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds a package dictionary in the repository pool by specifying a
|
* Finds a package dictionary in the repository pool by specifying a
|
||||||
* package pattern or a package name.
|
* package pattern or a package name. This function does not take into
|
||||||
|
* account virtual packages set in configuration file.
|
||||||
*
|
*
|
||||||
* @param[in] pkg Package pattern or name.
|
* @param[in] pkg Package pattern or name.
|
||||||
* @param[in] bypattern True if \a pkg is a pattern, false if it is a pkgname.
|
* @param[in] bypattern True if \a pkg is a pattern, false if it is a pkgname.
|
||||||
@ -1241,6 +1242,22 @@ int xbps_repository_pool_foreach(
|
|||||||
prop_dictionary_t
|
prop_dictionary_t
|
||||||
xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best);
|
xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a package dictionary in repository pool by specifying a
|
||||||
|
* package pattern or a package name. Only virtual packages set in
|
||||||
|
* configuration file will be matched.
|
||||||
|
*
|
||||||
|
* @param[in] pkg Virtual package pattern or name.
|
||||||
|
* @param[in] bypattern True if \a pkg is a pattern, false if it is a pkgname.
|
||||||
|
* @param[in] best True to find the best version available in repo, false to
|
||||||
|
* fetch the first package found matching its pkgname.
|
||||||
|
*
|
||||||
|
* @return The package dictionary if found, NULL otherwise.
|
||||||
|
*/
|
||||||
|
prop_dictionary_t
|
||||||
|
xbps_repository_pool_find_virtualpkg(const char *pkg,
|
||||||
|
bool bypattern, bool best);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over the the repository pool and search for a metadata plist
|
* Iterate over the the repository pool and search for a metadata plist
|
||||||
* file in a binary package named 'pkgname'. If a package is matched by
|
* file in a binary package named 'pkgname'. If a package is matched by
|
||||||
|
@ -242,10 +242,20 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
|
|||||||
/*
|
/*
|
||||||
* Check if package is already added in the
|
* Check if package is already added in the
|
||||||
* array of unsorted deps, and check if current required
|
* array of unsorted deps, and check if current required
|
||||||
* dependency pattern is matched.
|
* dependency pattern is matched. First checking if required
|
||||||
|
* dependency is supplied by a virtual pkg set in
|
||||||
|
* the configuration file.
|
||||||
*/
|
*/
|
||||||
curpkgd = xbps_find_pkg_in_dict_by_pattern(transd,
|
curpkgd = xbps_find_virtualpkg_conf_in_dict_by_pattern(transd,
|
||||||
"unsorted_deps", reqpkg);
|
"unsorted_deps", reqpkg);
|
||||||
|
if (curpkgd == NULL) {
|
||||||
|
/*
|
||||||
|
* Look for a real package matching pattern
|
||||||
|
* if no match.
|
||||||
|
*/
|
||||||
|
curpkgd = xbps_find_pkg_in_dict_by_pattern(transd,
|
||||||
|
"unsorted_deps", reqpkg);
|
||||||
|
}
|
||||||
if (curpkgd != NULL) {
|
if (curpkgd != NULL) {
|
||||||
prop_dictionary_get_cstring_nocopy(curpkgd,
|
prop_dictionary_get_cstring_nocopy(curpkgd,
|
||||||
"pkgver", &pkgver_q);
|
"pkgver", &pkgver_q);
|
||||||
@ -260,30 +270,35 @@ find_repo_deps(prop_dictionary_t transd, /* transaction dictionary */
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* If required pkgdep is not in repo, add it into the
|
* If required pkgdep (first virtual pkg in conf, otherwise
|
||||||
* missing deps array and pass to the next one.
|
* real pkg) is not in repo, add it into the missing deps
|
||||||
|
* array and pass to the next one.
|
||||||
*/
|
*/
|
||||||
curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, false);
|
curpkgd = xbps_repository_pool_find_virtualpkg(reqpkg, true, false);
|
||||||
if (curpkgd == NULL) {
|
if (curpkgd == NULL) {
|
||||||
if (errno && errno != ENOENT) {
|
curpkgd = xbps_repository_pool_find_pkg(reqpkg, true, false);
|
||||||
rv = errno;
|
if (curpkgd == NULL) {
|
||||||
break;
|
/* pkg not found, there was some error */
|
||||||
}
|
if (errno && errno != ENOENT) {
|
||||||
|
rv = errno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
rv = add_missing_reqdep(mrdeps, reqpkg);
|
rv = add_missing_reqdep(mrdeps, reqpkg);
|
||||||
if (rv != 0 && rv != EEXIST) {
|
if (rv != 0 && rv != EEXIST) {
|
||||||
xbps_dbg_printf_append("`%s': "
|
xbps_dbg_printf_append("`%s': "
|
||||||
"add_missing_reqdep failed %s\n", reqpkg);
|
"add_missing_reqdep failed %s\n", reqpkg);
|
||||||
break;
|
break;
|
||||||
} else if (rv == EEXIST) {
|
} else if (rv == EEXIST) {
|
||||||
xbps_dbg_printf_append("`%s' missing dep "
|
xbps_dbg_printf_append("`%s' missing dep "
|
||||||
"already added.\n", reqpkg);
|
"already added.\n", reqpkg);
|
||||||
rv = 0;
|
rv = 0;
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
xbps_dbg_printf_append("`%s' added "
|
xbps_dbg_printf_append("`%s' added "
|
||||||
"into the missing deps array.\n", reqpkg);
|
"into the missing deps array.\n", reqpkg);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pkgname = xbps_pkgpattern_name(reqpkg);
|
pkgname = xbps_pkgpattern_name(reqpkg);
|
||||||
|
@ -87,10 +87,14 @@ repository_find_pkg(const char *pattern, const char *reason)
|
|||||||
pkg_repod = xbps_repository_pool_find_pkg(pattern,
|
pkg_repod = xbps_repository_pool_find_pkg(pattern,
|
||||||
bypattern, bestpkg);
|
bypattern, bestpkg);
|
||||||
if (pkg_repod == NULL) {
|
if (pkg_repod == NULL) {
|
||||||
/* not found */
|
pkg_repod = xbps_repository_pool_find_virtualpkg(pattern,
|
||||||
rv = errno;
|
bypattern, bestpkg);
|
||||||
errno = 0;
|
if (pkg_repod == NULL) {
|
||||||
goto out;
|
/* not found */
|
||||||
|
rv = errno;
|
||||||
|
errno = 0;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Prepare transaction dictionary and missing deps array.
|
* Prepare transaction dictionary and missing deps array.
|
||||||
|
@ -387,11 +387,10 @@ repo_find_best_pkg_cb(struct repository_pool_index *rpi,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_dictionary_t
|
static struct repo_pool_fpkg *
|
||||||
xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
|
repo_find_pkg(const char *pkg, bool bypattern, bool best, bool virtual)
|
||||||
{
|
{
|
||||||
struct repo_pool_fpkg *rpf;
|
struct repo_pool_fpkg *rpf;
|
||||||
prop_dictionary_t pkgd = NULL;
|
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkg != NULL);
|
assert(pkg != NULL);
|
||||||
@ -411,37 +410,57 @@ xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
|
|||||||
* pattern in all repositories.
|
* pattern in all repositories.
|
||||||
*/
|
*/
|
||||||
rv = xbps_repository_pool_foreach(repo_find_best_pkg_cb, rpf);
|
rv = xbps_repository_pool_foreach(repo_find_best_pkg_cb, rpf);
|
||||||
if (rv != 0) {
|
if (rv != 0)
|
||||||
errno = rv;
|
errno = rv;
|
||||||
goto out;
|
|
||||||
} else if (rpf->pkgfound == false) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/*
|
if (virtual) {
|
||||||
* Look for any virtual package set by the user matching
|
|
||||||
* the package name or pattern.
|
|
||||||
*/
|
|
||||||
rv = xbps_repository_pool_foreach(repo_find_virtualpkg_cb, rpf);
|
|
||||||
if (rv != 0) {
|
|
||||||
errno = rv;
|
|
||||||
goto out;
|
|
||||||
} else if (rpf->pkgfound == false) {
|
|
||||||
/*
|
/*
|
||||||
* No virtual package found. Look for real package
|
* No package found. Look for virtual package
|
||||||
* names or patterns instead.
|
* set by the user or any virtual pkg available.
|
||||||
|
*/
|
||||||
|
rv = xbps_repository_pool_foreach(repo_find_virtualpkg_cb, rpf);
|
||||||
|
if (rv != 0)
|
||||||
|
errno = rv;
|
||||||
|
} else {
|
||||||
|
/*
|
||||||
|
* Look for a package (non virtual) in repositories.
|
||||||
*/
|
*/
|
||||||
rv = xbps_repository_pool_foreach(repo_find_pkg_cb, rpf);
|
rv = xbps_repository_pool_foreach(repo_find_pkg_cb, rpf);
|
||||||
if (rv != 0) {
|
if (rv != 0)
|
||||||
errno = rv;
|
errno = rv;
|
||||||
goto out;
|
|
||||||
} else if (rpf->pkgfound == false) {
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pkgd = prop_dictionary_copy(rpf->pkgd);
|
|
||||||
out:
|
return rpf;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_dictionary_t
|
||||||
|
xbps_repository_pool_find_virtualpkg(const char *pkg, bool bypattern, bool best)
|
||||||
|
{
|
||||||
|
struct repo_pool_fpkg *rpf;
|
||||||
|
prop_dictionary_t pkgd = NULL;
|
||||||
|
|
||||||
|
assert(pkg != NULL);
|
||||||
|
|
||||||
|
rpf = repo_find_pkg(pkg, bypattern, best, true);
|
||||||
|
if (rpf->pkgfound && rpf->pkgd != NULL)
|
||||||
|
pkgd = prop_dictionary_copy(rpf->pkgd);
|
||||||
|
free(rpf);
|
||||||
|
|
||||||
|
return pkgd;
|
||||||
|
}
|
||||||
|
|
||||||
|
prop_dictionary_t
|
||||||
|
xbps_repository_pool_find_pkg(const char *pkg, bool bypattern, bool best)
|
||||||
|
{
|
||||||
|
struct repo_pool_fpkg *rpf;
|
||||||
|
prop_dictionary_t pkgd = NULL;
|
||||||
|
|
||||||
|
assert(pkg != NULL);
|
||||||
|
|
||||||
|
rpf = repo_find_pkg(pkg, bypattern, best, false);
|
||||||
|
if (rpf->pkgfound && rpf->pkgd != NULL)
|
||||||
|
pkgd = prop_dictionary_copy(rpf->pkgd);
|
||||||
free(rpf);
|
free(rpf);
|
||||||
|
|
||||||
return pkgd;
|
return pkgd;
|
||||||
|
@ -71,7 +71,8 @@ pkgdep_find(const char *name, const char *trans)
|
|||||||
if (pd->d == NULL)
|
if (pd->d == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false)) {
|
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false)) {
|
||||||
if (trans == pd->trans)
|
if (trans && pd->trans &&
|
||||||
|
(strcmp(trans, pd->trans) == 0))
|
||||||
return pd;
|
return pd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -96,7 +97,8 @@ pkgdep_find_idx(const char *name, const char *trans)
|
|||||||
if (pd->d == NULL)
|
if (pd->d == NULL)
|
||||||
continue;
|
continue;
|
||||||
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false)) {
|
if (xbps_match_virtual_pkg_in_dict(pd->d, name, false)) {
|
||||||
if (trans == pd->trans)
|
if (trans && pd->trans &&
|
||||||
|
(strcmp(trans, pd->trans) == 0))
|
||||||
return idx;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,8 +158,14 @@ pkgdep_end(prop_array_t sorted)
|
|||||||
* Do not add duplicate pkg dictionaries with the
|
* Do not add duplicate pkg dictionaries with the
|
||||||
* same transaction reason into the sorted array.
|
* same transaction reason into the sorted array.
|
||||||
*/
|
*/
|
||||||
sorted_pkgd = xbps_find_pkg_in_array_by_name(sorted,
|
sorted_pkgd =
|
||||||
pd->name);
|
xbps_find_pkg_in_array_by_name(sorted, pd->name);
|
||||||
|
if (sorted_pkgd == NULL) {
|
||||||
|
/* find virtualpkg if no match */
|
||||||
|
sorted_pkgd =
|
||||||
|
xbps_find_virtualpkg_in_array_by_name(
|
||||||
|
sorted, pd->name);
|
||||||
|
}
|
||||||
if (sorted_pkgd == NULL) {
|
if (sorted_pkgd == NULL) {
|
||||||
prop_array_add(sorted, pd->d);
|
prop_array_add(sorted, pd->d);
|
||||||
pkgdep_release(pd);
|
pkgdep_release(pd);
|
||||||
@ -233,10 +241,13 @@ again:
|
|||||||
free(pkgnamedep);
|
free(pkgnamedep);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
/* Find pkg by name */
|
||||||
curpkgd = xbps_find_pkg_in_dict_by_name(transd,
|
curpkgd = xbps_find_pkg_in_dict_by_name(transd,
|
||||||
"unsorted_deps", pkgnamedep);
|
"unsorted_deps", pkgnamedep);
|
||||||
if (curpkgd == NULL) {
|
if (curpkgd == NULL) {
|
||||||
curpkgd = xbps_find_virtualpkg_in_dict_by_name(transd,
|
/* find virtualpkg by name if no match */
|
||||||
|
curpkgd =
|
||||||
|
xbps_find_virtualpkg_in_dict_by_name(transd,
|
||||||
"unsorted_deps", pkgnamedep);
|
"unsorted_deps", pkgnamedep);
|
||||||
}
|
}
|
||||||
if (curpkgd == NULL) {
|
if (curpkgd == NULL) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user