File: transaction.cpp

package info (click to toggle)
dnf5 5.4.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,960 kB
  • sloc: cpp: 94,312; python: 3,370; xml: 1,073; ruby: 600; sql: 250; ansic: 232; sh: 104; perl: 62; makefile: 30
file content (31 lines) | stat: -rw-r--r-- 979 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* includes; won't compile in tests, in the docs we leave out the comment lines to show them
#include <libdnf5/base/goal.hpp>
*/

// Create a goal
libdnf5::Goal goal(base);

// Add an RPM package named "one" for installation into the goal.
goal.add_rpm_install("one");

// Resolve the goal, create a transaction object.
auto transaction = goal.resolve();

if (transaction.get_problems() != libdnf5::GoalProblem::NO_PROBLEM) {
    for (auto message : transaction.get_resolve_logs_as_strings()) {
        std::cout << message << std::endl;
    }
}

// We can iterate over the resolved transaction and inspect the packages.
std::cout << "Resolved transaction:" << std::endl;
for (const auto & tspkg : transaction.get_transaction_packages()) {
    std::cout << tspkg.get_package().get_nevra() << ": " << transaction_item_action_to_string(tspkg.get_action())
              << std::endl;
}

// Download the packages.
transaction.download();

// Run the transaction.
transaction.run();