Skip to content

Commit

Permalink
Throw an error on invalid repo input for setopt and *repo options
Browse files Browse the repository at this point in the history
Options `--setopt`, `--enable-repo`, `--disable-repo` and `--repo` will
not accept repo-id vaule that doesn't match any configured repository.

This is different to dnf4 where only `--repo` and `--enablerepo` throw
an error on invalid repo id. `--disablerepo` just shows a warning and
`--setopt` doesn't show any problem.
In dnf4 the error also depends on `strict` conf option but this is
deprecated in dnf5. dnf5 is strict by default.
  • Loading branch information
kontura committed Dec 13, 2023
1 parent 229fc78 commit ecdb903
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dnf5/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "download_callbacks.hpp"
#include "plugins.hpp"
#include "utils/string.hpp"
#include "utils/url.hpp"

#include <fmt/format.h>
Expand Down Expand Up @@ -99,12 +100,16 @@ Context::~Context() {

// TODO(jrohel): Move logic into libdnf?
void Context::apply_repository_setopts() {
std::vector<std::string> missing_repo_ids;
for (const auto & setopt : setopts) {
auto last_dot_pos = setopt.first.rfind('.');
auto repo_pattern = setopt.first.substr(0, last_dot_pos);
libdnf5::repo::RepoQuery query(base);
query.filter_id(repo_pattern, libdnf5::sack::QueryCmp::GLOB);
query.filter_type(libdnf5::repo::Repo::Type::AVAILABLE);
if (query.empty()) {
missing_repo_ids.push_back(repo_pattern);
}
auto key = setopt.first.substr(last_dot_pos + 1);
for (auto & repo : query) {
try {
Expand All @@ -115,6 +120,11 @@ void Context::apply_repository_setopts() {
}
}
}

if (!missing_repo_ids.empty()) {
throw libdnf5::cli::ArgumentParserError(
M_("No matching repositories for \"{}\""), libdnf5::utils::string::join(missing_repo_ids, ", "));
}
}


Expand Down
5 changes: 5 additions & 0 deletions doc/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ The functionality is now split to two config options - ``skip_broken`` for the u
corresponding command line options ``--skip-broken`` and ``--skip-unavailable`` for commands where it makes sense.


Global options
--------------
* Options ``--disable-repo=REPO_ID`` and ``--setopt=[REPO_ID.]OPTION=VALUE`` now always cause an error when provided with invalid ``REPO_ID``.
This makes them consistent with ``--repo=REPO_ID`` and ``--enable-repo=REPO_ID``. The ``strict`` configuration option is no longer taken into account.

Alias command
-------------
* Dropped. The command is replaced by a different functionality, see
Expand Down

0 comments on commit ecdb903

Please sign in to comment.