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

repo: Error out on creating repo with duplicate id #802

Merged
merged 2 commits into from
Aug 8, 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
3 changes: 3 additions & 0 deletions dnf5/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,9 @@ int main(int argc, char * argv[]) try {
any_repos_from_system_configuration = repo_sack->size() > 0;

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");
}

context.apply_repository_setopts();

Expand Down
5 changes: 5 additions & 0 deletions include/libdnf5/repo/repo_errors.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ class RepoRpmError : public RepoError {
const char * get_name() const noexcept override { return "RepoRpmError"; }
};

class RepoIdAlreadyExistsError : public RepoError {
using RepoError::RepoError;
const char * get_name() const noexcept override { return "RepoIdAlreadyExistsError"; }
};

} // namespace libdnf5::repo

#endif
7 changes: 6 additions & 1 deletion libdnf5/repo/repo_sack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ RepoSack::RepoSack(libdnf5::Base & base) : RepoSack(base.get_weak_ptr()) {}


RepoWeakPtr RepoSack::create_repo(const std::string & id) {
// TODO(jrohel): Test repo exists
for (const auto & existing_repo : get_data()) {
if (existing_repo->get_id() == id) {
throw RepoIdAlreadyExistsError(
M_("Failed to create repo \"{}\": Id is present more than once in the configuration"), id);
}
}
auto repo = std::make_unique<Repo>(base, id, Repo::Type::AVAILABLE);
return add_item_with_return(std::move(repo));
}
Expand Down
Loading