class Base

Instances of :class:libdnf5::Base are the central point of functionality supplied by libdnf5. An application will typically create a single instance of this class which it will keep for the run-time needed to accomplish its packaging tasks. :class:.Base instances are stateful objects owning various data.

Public Functions

Base(std::vector<std::unique_ptr<Logger>> &&loggers = {})

Constructs a new Base instance and sets the destination loggers.

void set_download_callbacks(std::unique_ptr<repo::DownloadCallbacks> &&download_callbacks)
repo::DownloadCallbacks *get_download_callbacks()
void lock()

Sets the pointer to the locked instance “Base” to “this” instance. Blocks if the pointer is already set. Pointer to a locked “Base” instance can be obtained using “get_locked_base()”.

void unlock()

Resets the pointer to a locked “Base” instance to “nullptr”. Throws an exception if another or no instance is locked.

void load_config()

Loads main configuration. The file defined in the current configuration and files in the drop-in directories are used.

ConfigMain &get_config()

a reference to configuration

LogRouterWeakPtr get_logger()
repo::RepoSackWeakPtr get_repo_sack()
rpm::PackageSackWeakPtr get_rpm_package_sack()
module::ModuleSackWeakPtr get_module_sack()
void enable_disable_plugins(const std::vector<std::string> &plugin_names, bool enable)

Adds a request to enable/disable plugins that match the names (glob patterns) in the list. Can be called multiple times. Requests (plugin_names and enable state) are queued. The enable state of a plugin is set according to the last matching request. Must be called before the Base::setup.

  • plugin_names – Plugin names (glob patterns) to enable/disable

  • enable – Request: true - enable plugins, false - disable plugins


libdnf5::UserAssertionError – When called after Base::setup

const std::vector<plugin::PluginInfo> &get_plugins_info() const

libdnf5::UserAssertionError – When called before Base::setup


a list of information about plugins found during Base::setup

void setup()

Loads libdnf plugins, vars from environment, varsdirs and installroot (releasever, arch) and resolves configuration of protected_packages (glob:). To prevent differences between configuration and internal Base settings, following configurations will be locked: installroot, varsdir. The method is supposed to be called after configuration and vars are updated, application plugins applied their pre configuration modification in configuration, but before repositories are loaded or any Package or Advisory query created. The method is recommended to be called before loading repositories, because not all variables for substitutions might be available. Caution - modification of vars after this call might be problematic, because architecture is already fixed for our solver. Calling the method for the second time result in throwing an exception

bool is_initialized()

Returns true when setup() (mandatory method in many workflows) was already called.

void notify_repos_configured()

Notifies the libdnf5 library that the repositories are configured. It can be called before load_repos. The libdnf5 library can then call plugins that can make final adjustments to the repositories configuration. In the case that it has not been called, it is called automatically at the beginning of the load_repos method. Calling the method for the second time result in throwing an exception.

bool are_repos_configured() const noexcept

Returns true when notify_repos_configured() was already called (by user or automatically)

transaction::TransactionHistoryWeakPtr get_transaction_history()


This method is experimental/unstable and should not be relied on. It may be removed without warning

VarsWeakPtr get_vars()

Gets base variables. They can be used in configuration files. Syntax in the config - ${var_name} or $var_name.

libdnf5::BaseWeakPtr get_weak_ptr()

Public Static Functions

static Base *get_locked_base() noexcept

Returns a pointer to a locked “Base” instance or “nullptr” if no instance is locked.


friend class libdnf5::InternalBaseUser
friend class libdnf5::base::Transaction
friend class libdnf5::Goal
friend class libdnf5::rpm::Package
friend class libdnf5::comps::Group
friend class libdnf5::comps::Environment
friend class libdnf5::advisory::AdvisoryQuery
friend class libdnf5::module::ModuleDB
friend class libdnf5::module::ModuleSack
friend class libdnf5::repo::RepoSack
friend class libdnf5::repo::SolvRepo