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

Throw an error on invalid repo input for setopt and *repo options #1064

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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 dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,11 @@ int main(int argc, char * argv[]) try {
repo_sack->create_repos_from_system_configuration();
any_repos_from_system_configuration = repo_sack->size() > 0;

auto vars = base.get_vars();
for (auto & id_path_pair : context.repos_from_path) {
id_path_pair.first = vars->substitute(id_path_pair.first);
id_path_pair.second = vars->substitute(id_path_pair.second);
}
repo_sack->create_repos_from_paths(context.repos_from_path, libdnf5::Option::Priority::COMMANDLINE);
for (const auto & [id, path] : context.repos_from_path) {
context.setopts.emplace_back(id + ".enabled", "1");
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
8 changes: 3 additions & 5 deletions libdnf5/repo/repo_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -601,13 +601,11 @@ void RepoSack::create_repos_from_reposdir() {

void RepoSack::create_repos_from_paths(
const std::vector<std::pair<std::string, std::string>> & repos_paths, libdnf5::Option::Priority priority) {
auto vars = base->get_vars();
for (const auto & [id, path] : repos_paths) {
auto repo_id = vars->substitute(id);
auto new_repo = create_repo(repo_id);
auto new_repo = create_repo(id);
auto & new_repo_config = new_repo->get_config();
new_repo_config.get_name_option().set(priority, repo_id);
new_repo_config.get_baseurl_option().set(priority, {vars->substitute(path)});
new_repo_config.get_name_option().set(priority, id);
new_repo_config.get_baseurl_option().set(priority, path);
}
}

Expand Down
Loading