2. Creating and configuring a session

 1#include <libdnf/base/base.hpp>
 2
 3// Create a new Base object.
 4libdnf::Base base;
 5
 6// Optionally load configuration from the config file.
 7//
 8// The Base's config is initialized with default values, one of which is
 9// `config_file_path()`. This contains the default path to the config file
10// ("/etc/dnf/dnf.conf"). Set a custom value and call the below method to load
11// configuration from a different location.
12base.load_config_from_file();
13
14// Optionally set installroot.
15//
16// Installroot is set to '/' when we're working with the system, but we can set
17// it to a different location. The Base instance will then work with the
18// installroot directory tree as its root for the rest of its lifetime.
19base.get_config().installroot().set(libdnf::Option::Priority::RUNTIME, installroot);
20
21// Load vars and do other initialization (of libsolv pool, etc.) based on the
22// configuration.  Locks the installroot and varsdir configuration values so
23// that they can't be changed.
24base.setup();