openSUSE / libsolv

Library for solving packages and reading repositories
http://en.opensuse.org/openSUSE:Libzypp_satsolver
Other
509 stars 151 forks source link

Extend unneeded packages by weak dependencies #553

Open j-mracek opened 4 months ago

j-mracek commented 4 months ago

We've got a request (https://issues.redhat.com/browse/RHEL-27937) to extend functionality of autoremove command to also remove optionally weak dependencies as unneeded packages.

The current implementation uses empty job and then we use void solver_get_unneeded(Solver *solv, Queue *unneededq, int filtered); to get unneeded packages. The result is identical if solverflags contains ignorerecommended or not (see https://github.com/rpm-software-management/libdnf/blob/ef8ac7fcedea1ec87dd3149ce1abdf8daeee25b9/libdnf/sack/query.cpp#L2248).

I would like to ask you whether the functionality is supported by libsolv and how we can use it?

I will be happy to provide additional information but I discover that classical testcase does not show unneeded packages. Anyway here is a test case:

repo @System 0 testtags <inline>
#>=Pkg: pkg-A 1.0 1 noarch
#>=Prv: pkg-A = 1.0-1
#>=Rec: pkg-B
#>=Pkg: pkg-B 1.0 1 noarch
#>=Prv: pkg-B = 1.0-1

system x86_64 rpm @System
poolflags implicitobsoleteusescolors whatprovideswithdisabled
solverflags allowdowngrade allowvendorchange ignorerecommended keepexplicitobsoletes bestobeypolicy keeporphans yumobsoletes
job userinstalled pkg pkg-A-1.0-1.noarch@@System
result transaction,problems <inline>

Expectation: Detect somehow pkg-B as unneeded packages when solver is supposed to ignore weak dependencies. I am completely fine if we will use another method, solver flag to get such information.

Conan-Kudo commented 4 months ago

Does it work if you add SOLVER_FLAG_STRONG_RECOMMENDS / strongrecommends? I believe that upgrades weak dependencies to count as "strong" dependencies (e.g. Requires) and may influence this as you wish.

mlschroe commented 4 months ago

So you want 'dnf autoremove` remove all weakdeps packages if install_weak_deps us set to false? I.e. the install_weak_deps state at the time where the package was installed should not matter? Or do you want to store the install_weak_deps in the dnf package db like the "autoinstalled" state?

Conan-Kudo commented 4 months ago

The idea is that dnf autoremove should be able to find all non-userinstalled packages to remove, including those weak installed.

j-mracek commented 4 months ago

I believe that user wants to cut from the system all optional packages that were not installed by user. In past, those dependencies (Recommends) could be installed because install_weak_deps=True or in past there were installed as hard dependency but now they are only recommended.