Skip to content

Commit

Permalink
Add new SOLVER_FLAG_FOCUS_NEW focus type
Browse files Browse the repository at this point in the history
First resolve the given jobs, then the dependencies of the
resulting packages ignoreing the ones provided by currently
installed packages. After that resolve all already installed
packages. This is similar to SOLVER_FLAG_FOCUS_BEST but less
aggressive in updating packages.

Fixes issue #549
  • Loading branch information
mlschroe committed Jul 9, 2024
1 parent 5c3047a commit 8151b3a
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 5 deletions.
1 change: 1 addition & 0 deletions bindings/solv.i
Original file line number Diff line number Diff line change
Expand Up @@ -3887,6 +3887,7 @@ returnself(matchsolvable)
static const int SOLVER_FLAG_INSTALL_ALSO_UPDATES = SOLVER_FLAG_INSTALL_ALSO_UPDATES;
static const int SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED = SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED;
static const int SOLVER_FLAG_STRICT_REPO_PRIORITY = SOLVER_FLAG_STRICT_REPO_PRIORITY;
static const int SOLVER_FLAG_FOCUS_NEW = SOLVER_FLAG_FOCUS_NEW;

static const int SOLVER_REASON_UNRELATED = SOLVER_REASON_UNRELATED;
static const int SOLVER_REASON_UNIT_RULE = SOLVER_REASON_UNIT_RULE;
Expand Down
9 changes: 7 additions & 2 deletions doc/gen/libsolv-bindings.3
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
.\" Title: Libsolv-Bindings
.\" Author: [see the "Author" section]
.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/>
.\" Date: 03/27/2024
.\" Date: 07/09/2024
.\" Manual: LIBSOLV
.\" Source: libsolv
.\" Language: English
.\"
.TH "LIBSOLV\-BINDINGS" "3" "03/27/2024" "libsolv" "LIBSOLV"
.TH "LIBSOLV\-BINDINGS" "3" "07/09/2024" "libsolv" "LIBSOLV"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
Expand Down Expand Up @@ -4101,6 +4101,11 @@ Resolve installed packages before resolving the given jobs\&. Setting this flag
First resolve the given jobs, then the dependencies of the resulting packages, then resolve all already installed packages\&. This will result in more packages being updated as when the flag is not used\&.
.RE
.PP
\fBSOLVER_FLAG_FOCUS_NEW\fR
.RS 4
First resolve the given jobs, then the dependencies of the resulting packages ignoreing the ones provided by currently installed packages\&. After that resolve all already installed packages\&. This is similar to SOLVER_FLAG_FOCUS_BEST but less aggressive in updating packages\&.
.RE
.PP
\fBSOLVER_FLAG_INSTALL_ALSO_UPDATES\fR
.RS 4
Update the package if a job is already fulfilled by an installed package\&.
Expand Down
7 changes: 7 additions & 0 deletions doc/libsolv-bindings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2450,6 +2450,13 @@ resulting packages, then resolve all already installed
packages. This will result in more packages being updated
as when the flag is not used.

*SOLVER_FLAG_FOCUS_NEW*::
First resolve the given jobs, then the dependencies of the
resulting packages ignoreing the ones provided by currently
installed packages. After that resolve all already installed
packages. This is similar to SOLVER_FLAG_FOCUS_BEST but less
aggressive in updating packages.

*SOLVER_FLAG_INSTALL_ALSO_UPDATES*::
Update the package if a job is already fulfilled by an installed
package.
Expand Down
1 change: 1 addition & 0 deletions ext/testcase.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static struct solverflags2str {
{ SOLVER_FLAG_INSTALL_ALSO_UPDATES, "installalsoupdates", 0 },
{ SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED, "onlynamespacerecommended", 0 },
{ SOLVER_FLAG_STRICT_REPO_PRIORITY, "strictrepopriority", 0 },
{ SOLVER_FLAG_FOCUS_NEW, "focusnew", 0 },
{ 0, 0, 0 }
};

Expand Down
23 changes: 20 additions & 3 deletions src/solver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,8 @@ solver_get_flag(Solver *solv, int flag)
return solv->break_orphans;
case SOLVER_FLAG_FOCUS_INSTALLED:
return solv->focus_installed;
case SOLVER_FLAG_FOCUS_NEW:
return solv->focus_new;
case SOLVER_FLAG_FOCUS_BEST:
return solv->focus_best;
case SOLVER_FLAG_YUM_OBSOLETES:
Expand Down Expand Up @@ -1664,6 +1666,9 @@ solver_set_flag(Solver *solv, int flag, int value)
case SOLVER_FLAG_FOCUS_INSTALLED:
solv->focus_installed = value;
break;
case SOLVER_FLAG_FOCUS_NEW:
solv->focus_new = value;
break;
case SOLVER_FLAG_FOCUS_BEST:
solv->focus_best = value;
break;
Expand Down Expand Up @@ -2071,7 +2076,7 @@ resolve_dependencies(Solver *solv, int level, int disablerules, Queue *dq)
Rule *r;
int origlevel = level;
Id p, *dp;
int focusbest = solv->focus_best && solv->do_extra_reordering;
int focusbest = (solv->focus_new || solv->focus_best) && solv->do_extra_reordering;
Repo *installed = solv->installed;

/*
Expand Down Expand Up @@ -2113,6 +2118,18 @@ resolve_dependencies(Solver *solv, int level, int disablerules, Queue *dq)
if (!p)
continue; /* sorry */
}
if (!solv->focus_best)
{
/* check that no positive literal is already installed */
if (r->p > 1 && pool->solvables[r->p].repo == installed)
continue;
dp = pool->whatprovidesdata + r->d;
while ((p = *dp++) != 0)
if (p > 1 && pool->solvables[p].repo == installed)
break;
if (p)
continue;
}
}
if (dq->count)
queue_empty(dq);
Expand Down Expand Up @@ -2898,8 +2915,8 @@ solver_run_sat(Solver *solv, int disablerules, int doweak)
systemlevel = level + 1;
}

/* resolve job dependencies in the focus_best case */
if (level < systemlevel && solv->focus_best && !solv->focus_installed && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
/* resolve job dependencies in the focus_new/best case */
if (level < systemlevel && (solv->focus_new || solv->focus_best) && !solv->focus_installed && solv->installed && solv->installed->nsolvables && !solv->installed->disabled)
{
solv->do_extra_reordering = 1;
olevel = level;
Expand Down
2 changes: 2 additions & 0 deletions src/solver.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ struct s_Solver {
int noautotarget; /* true: do not assume targeted for up/dup jobs that contain no installed solvable */
int focus_installed; /* true: resolve update rules first */
int focus_best; /* true: resolve job dependencies first */
int focus_new; /* true: resolve job dependencies first but ignore dependencies met by installed packages */
int do_yum_obsoletes; /* true: add special yumobs rules */
int urpmreorder; /* true: do special urpm package reordering */
int strongrecommends; /* true: create weak rules for recommends */
Expand Down Expand Up @@ -337,6 +338,7 @@ typedef struct s_Solver Solver;
#define SOLVER_FLAG_INSTALL_ALSO_UPDATES 26
#define SOLVER_FLAG_ONLY_NAMESPACE_RECOMMENDED 27
#define SOLVER_FLAG_STRICT_REPO_PRIORITY 28
#define SOLVER_FLAG_FOCUS_NEW 29

#define GET_USERINSTALLED_NAMES (1 << 0) /* package names instead of ids */
#define GET_USERINSTALLED_INVERTED (1 << 1) /* autoinstalled */
Expand Down
27 changes: 27 additions & 0 deletions test/testcases/focus/new1.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repo @System 0 testtags <inline>
#>=Pkg: krb5-libs 1.18.2 22.el8_7 x86_64
#>=Prv: krb5-libs(x86-64) = 1.18.2-22.el8_7

repo available 0 testtags <inline>
#>=Pkg: ipa-client 4.9.11 5.el8 x86_64
#>=Req: krb5-pkinit-openssl
#>
#>=Pkg: krb5-libs 1.18.2 25.el8_8 x86_64
#>=Prv: krb5-libs(x86-64) = 1.18.2-25.el8_8
#>
#>=Pkg: krb5-pkinit 1.18.2 25.el8_8 x86_64
#>=Req: krb5-libs(x86-64) = 1.18.2-25.el8_8
#>=Prv: krb5-pkinit-openssl = 1.18.2-25.el8_8
#>
#>=Pkg: krb5-pkinit 1.18.2 22.el8_7 x86_64
#>=Req: krb5-libs(x86-64) = 1.18.2-22.el8_7
#>=Prv: krb5-pkinit-openssl = 1.18.2-22.el8_7

system x86_64 rpm @System
solverflags focusnew

job install pkg ipa-client-4.9.11-5.el8.x86_64@available
result transaction,problems <inline>
#>install ipa-client-4.9.11-5.el8.x86_64@available
#>install krb5-pkinit-1.18.2-25.el8_8.x86_64@available
#>upgrade krb5-libs-1.18.2-22.el8_7.x86_64@@System krb5-libs-1.18.2-25.el8_8.x86_64@available
26 changes: 26 additions & 0 deletions test/testcases/focus/new2.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
repo @System 0 testtags <inline>
#>=Pkg: krb5-libs 1.18.2 22.el8_7 x86_64
#>=Prv: krb5-libs(x86-64) = 1.18.2-22.el8_7

repo available 0 testtags <inline>
#>=Pkg: ipa-client 4.9.11 5.el8 x86_64
#>=Req: krb5-pkinit-openssl
#>
#>=Pkg: krb5-libs 1.18.2 25.el8_8 x86_64
#>=Prv: krb5-libs(x86-64) = 1.18.2-25.el8_8
#>
#>=Pkg: krb5-pkinit 1.18.2 25.el8_8 x86_64
#>=Req: krb5-libs(x86-64)
#>=Prv: krb5-pkinit-openssl = 1.18.2-25.el8_8
#>
#>=Pkg: krb5-pkinit 1.18.2 22.el8_7 x86_64
#>=Req: krb5-libs(x86-64)
#>=Prv: krb5-pkinit-openssl = 1.18.2-22.el8_7

system x86_64 rpm @System
solverflags focusnew

job install pkg ipa-client-4.9.11-5.el8.x86_64@available
result transaction,problems <inline>
#>install ipa-client-4.9.11-5.el8.x86_64@available
#>install krb5-pkinit-1.18.2-25.el8_8.x86_64@available

0 comments on commit 8151b3a

Please sign in to comment.