Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit queries to nevra forms when provided by command #2098

Merged
merged 2 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions dnf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2064,9 +2064,14 @@ def install_specs(self, install, exclude=None, reponame=None, strict=True, forms
def install(self, pkg_spec, reponame=None, strict=True, forms=None):
# :api
"""Mark package(s) given by pkg_spec and reponame for installation."""
kwargs = {'forms': forms, 'with_src': False}
if forms:
kwargs['with_nevra'] = True
kwargs['with_provides'] = False
kwargs['with_filenames'] = False

subj = dnf.subject.Subject(pkg_spec)
solution = subj.get_best_solution(self.sack, forms=forms, with_src=False)
solution = subj.get_best_solution(self.sack, **kwargs)

if self.conf.multilib_policy == "all" or subj._is_arch_specified(solution):
q = solution['query']
Expand Down Expand Up @@ -2306,8 +2311,13 @@ def autoremove(self, forms=None, pkg_specs=None, grp_specs=None, filenames=None)
def remove(self, pkg_spec, reponame=None, forms=None):
# :api
"""Mark the specified package for removal."""
kwargs = {'forms': forms}
if forms:
kwargs['with_nevra'] = True
kwargs['with_provides'] = False
kwargs['with_filenames'] = False

matches = dnf.subject.Subject(pkg_spec).get_best_query(self.sack, forms=forms)
matches = dnf.subject.Subject(pkg_spec).get_best_query(self.sack, **kwargs)
installed = [
pkg for pkg in matches.installed()
if reponame is None or
Expand Down
5 changes: 3 additions & 2 deletions dnf/cli/commands/repoquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,9 +461,10 @@ def run(self):
if self.opts.key:
remote_packages = self._add_add_remote_packages()

kwark = {}
kwark = {'with_provides': False}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably enhance also repoquery documentation a bit to prevent future misunderstandings. It correctly states that query keys are <package-file-spec>. But it also says:

<package-file-spec>
              Package specification in the  NEVRA  format
              (name[-[epoch:]version[-re‐lease]][.arch]),  a  package  provide
              or a file provide. See Specifying Packages.

I think we should remove the a package provide part from it since repoquery command has never searched in provides.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

if self.opts.command in self.nevra_forms:
kwark["forms"] = [self.nevra_forms[self.opts.command]]
kwark['with_filenames'] = False
pkgs = []
query_results = q.filter(empty=True)

Expand All @@ -474,7 +475,7 @@ def run(self):
for key in self.opts.key:
query_results = query_results.union(
dnf.subject.Subject(key, ignore_case=True).get_best_query(
self.base.sack, with_provides=False, query=q, **kwark))
self.base.sack, query=q, **kwark))
q = query_results

if self.opts.recent:
Expand Down
6 changes: 5 additions & 1 deletion doc/api_base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@
.. method:: install(pkg_spec, reponame=None, strict=True, forms=None)

Mark packages matching `pkg_spec` for installation.
`reponame` can be a name of a repository or a list of repository names. If given, the selection of available packages is limited to packages from these repositories. If strict is set to False, the installation ignores packages with dependency solving problems. Parameter `forms` has the same meaning as in :meth:`dnf.subject.Subject.get_best_query`.
`reponame` can be a name of a repository or a list of repository names. If given, the selection of available
packages is limited to packages from these repositories. If strict is set to False, the installation ignores
packages with dependency solving problems. Parameter `forms` is list of pattern forms from `hawkey`_.
Leaving the parameter to ``None`` results in using a reasonable default list of forms. When forms is specified,
method will not match `pkg_spec` with provides and file provides.

.. method:: package_downgrade(pkg, strict=False)

Expand Down
7 changes: 5 additions & 2 deletions doc/command_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,8 @@ Install Command
are considered correct, the resulting package is picked simply by lexicographical order.

There are also a few specific install commands ``install-n``, ``install-na`` and
``install-nevra`` that allow the specification of an exact argument in the NEVRA format.
``install-nevra`` that allow the specification of an exact argument in the NEVRA format. As a consequence, <spec>
will be not matched with provides and file provides.

See also :ref:`\configuration_files_replacement_policy-label`.

Expand Down Expand Up @@ -1191,7 +1192,8 @@ Remove Command
Removes old installonly packages, keeping only latest versions and version of running kernel.

There are also a few specific remove commands ``remove-n``, ``remove-na`` and ``remove-nevra``
that allow the specification of an exact argument in the NEVRA format.
that allow the specification of an exact argument in the NEVRA format. As a consequence, <spec>
will be not matched with provides and file provides.

Remove Examples
---------------
Expand Down Expand Up @@ -1255,6 +1257,7 @@ Repoquery Command

There are also a few specific repoquery commands ``repoquery-n``, ``repoquery-na`` and ``repoquery-nevra``
that allow the specification of an exact argument in the NEVRA format (does not affect arguments of options like --whatprovides <arg>, ...).
As a consequence, <spec> will be not matched with file provides.

Select Options
--------------
Expand Down
Loading