Commit 2ea61da9 authored by Timo Teräs's avatar Timo Teräs

add: make repository tag pinning stronger

Previously we would not upgrade just by doing "apk add foo@tag" if
foo was already installed. It required explicit '-u'. This allows
'apk add' to explicitly prefer the newly specified pinning.
parent 1f9a36de
...@@ -127,7 +127,7 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv) ...@@ -127,7 +127,7 @@ static int add_main(void *ctx, struct apk_database *db, int argc, char **argv)
if (virtpkg == NULL) { if (virtpkg == NULL) {
apk_deps_add(&world, &dep); apk_deps_add(&world, &dep);
apk_solver_set_name_flags(dep.name, apk_solver_set_name_flags(dep.name,
actx->solver_flags, actx->solver_flags | APK_SOLVERF_PREFER_TAG,
actx->solver_flags); actx->solver_flags);
} else { } else {
apk_deps_add(&virtpkg->depends, &dep); apk_deps_add(&virtpkg->depends, &dep);
......
...@@ -25,6 +25,7 @@ struct apk_changeset { ...@@ -25,6 +25,7 @@ struct apk_changeset {
#define APK_SOLVERF_UPGRADE 0x0001 #define APK_SOLVERF_UPGRADE 0x0001
#define APK_SOLVERF_AVAILABLE 0x0002 #define APK_SOLVERF_AVAILABLE 0x0002
#define APK_SOLVERF_REINSTALL 0x0004 #define APK_SOLVERF_REINSTALL 0x0004
#define APK_SOLVERF_PREFER_TAG 0x0008
void apk_solver_set_name_flags(struct apk_name *name, void apk_solver_set_name_flags(struct apk_name *name,
unsigned short solver_flags, unsigned short solver_flags,
......
...@@ -287,13 +287,21 @@ static int compare_package_preference(unsigned short solver_flags, ...@@ -287,13 +287,21 @@ static int compare_package_preference(unsigned short solver_flags,
struct apk_package *pkgA, struct apk_package *pkgA,
struct apk_package *pkgB) struct apk_package *pkgB)
{ {
/* preferred repository pinning */ if (solver_flags & APK_SOLVERF_PREFER_TAG) {
if ((pkgA->ipkg || pkgA->filename || (pkgA->repos & preferred_repos)) && /* preferred repository pinning */
!(pkgB->ipkg || pkgB->filename || (pkgB->repos & preferred_repos))) if ((pkgA->repos & preferred_repos) && !(pkgB->repos & preferred_repos))
return 1; return 1;
if ((pkgB->ipkg || pkgA->filename || (pkgB->repos & preferred_repos)) && if ((pkgB->repos & preferred_repos) && !(pkgA->repos & preferred_repos))
!(pkgA->ipkg || pkgB->filename || (pkgA->repos & preferred_repos))) return -1;
return -1; } else {
/* preferred repository pinning */
if ((pkgA->ipkg || pkgA->filename || (pkgA->repos & preferred_repos)) &&
!(pkgB->ipkg || pkgB->filename || (pkgB->repos & preferred_repos)))
return 1;
if ((pkgB->ipkg || pkgA->filename || (pkgB->repos & preferred_repos)) &&
!(pkgA->ipkg || pkgB->filename || (pkgA->repos & preferred_repos)))
return -1;
}
if (solver_flags & APK_SOLVERF_AVAILABLE) { if (solver_flags & APK_SOLVERF_AVAILABLE) {
if (pkgA->repos != 0 && pkgB->repos == 0) if (pkgA->repos != 0 && pkgB->repos == 0)
...@@ -332,10 +340,13 @@ static int get_preference(struct apk_solver_state *ss, ...@@ -332,10 +340,13 @@ static int get_preference(struct apk_solver_state *ss,
unsigned short name_flags = ns->solver_flags_local unsigned short name_flags = ns->solver_flags_local
| ns->solver_flags_inherited | ns->solver_flags_inherited
| ss->solver_flags; | ss->solver_flags;
unsigned int preferred_repos = ns->preferred_repos | ss->db->repo_tags[0].allowed_repos; unsigned int preferred_repos = ns->preferred_repos;
unsigned short preference = 0; unsigned short preference = 0;
int i; int i;
if (preferred_repos == 0)
preferred_repos = ss->db->repo_tags[0].allowed_repos;
for (i = 0; i < name->pkgs->num; i++) { for (i = 0; i < name->pkgs->num; i++) {
struct apk_package *pkg0 = name->pkgs->item[i]; struct apk_package *pkg0 = name->pkgs->item[i];
struct apk_package_state *ps0 = pkg_to_ps(pkg0); struct apk_package_state *ps0 = pkg_to_ps(pkg0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment