3. Loading repositories

These tutorials are follow-ups to Creating and configuring a session, you can prepend it directly for a functional piece of code.

3.1. Load repositories from system configuration files

 1auto repo_sack = base.get_repo_sack();
 2
 3// Create repositories from system configuration files.
 4repo_sack->create_repos_from_system_configuration();
 5
 6// If out of date, downloads fresh repositories' metadata and loads the
 7// repositories into memory.
 8//
 9// `true` as first argument says to also load the @System repository (the
10// packages installed on the system, loaded from the rpmdb).
11repo_sack->update_and_load_enabled_repos(true);

3.2. Load a custom repository

 1auto repo_sack = base.get_repo_sack();
 2
 3// Create a new repo with the given id.
 4//
 5// The repo is a weak pointer to an object owned by the repo sack.
 6auto repo = repo_sack->create_repo("my_new_repo_id");
 7
 8// Configure the repo.
 9//
10// Setting at least one of the baseurl, mirrorlist or metalink options is
11// mandatory.
12//
13// baseurl examples:
14// * /absolute/path/
15// * file:///absolute/path/url/
16// * https://example.com/url/
17repo->get_config().baseurl().set(libdnf::Option::Priority::RUNTIME, baseurl);
18
19// If out of date, downloads fresh metadata of all available repositories and
20// loads the repositories into memory.
21//
22// `false` as first argument says not to load the @System repository (the
23// packages installed on the system).
24repo_sack->update_and_load_enabled_repos(false);