Skip to content

Commit

Permalink
transaction: Save the reason for installing
Browse files Browse the repository at this point in the history
It doesn't make sense to look for the reason in the history, as the
package is not installed yet.
We can get the reason of a package being installed from hawkey.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1733274
  • Loading branch information
aleasto committed Sep 30, 2023
1 parent e7cf3d1 commit b2cdd7c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions libdnf/dnf-transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ _get_current_time()
* avoid the lookup in the rpmdb.
**/
static void
_history_write_item(DnfPackage *pkg, libdnf::Swdb *swdb, libdnf::TransactionItemAction action)
_history_write_item(DnfPackage *pkg, libdnf::Swdb *swdb, libdnf::TransactionItemAction action, libdnf::TransactionItemReason reason)
{
auto rpm = swdb->createRPMItem();
rpm->setName(dnf_package_get_name(pkg));
Expand All @@ -878,8 +878,9 @@ _history_write_item(DnfPackage *pkg, libdnf::Swdb *swdb, libdnf::TransactionItem
rpm->setArch(dnf_package_get_arch(pkg));
rpm->save();

libdnf::TransactionItemReason reason =
swdb->resolveRPMTransactionItemReason(rpm->getName(), rpm->getArch(), -2);
if (reason == libdnf::TransactionItemReason::UNKNOWN) {
reason = swdb->resolveRPMTransactionItemReason(rpm->getName(), rpm->getArch(), -2);
}

auto transItem = swdb->addItem(
std::dynamic_pointer_cast< libdnf::Item >(rpm), dnf_package_get_reponame(pkg), action, reason);
Expand Down Expand Up @@ -1236,8 +1237,20 @@ dnf_transaction_commit(DnfTransaction *transaction, HyGoal goal, DnfState *state
swdbAction = libdnf::TransactionItemAction::REINSTALL;
}

libdnf::TransactionItemReason swdbReason;
switch (hy_goal_get_reason(goal, pkg)) {
case HY_REASON_USER:
swdbReason = libdnf::TransactionItemReason::USER;
break;
case HY_REASON_DEP:
swdbReason = libdnf::TransactionItemReason::DEPENDENCY;
break;
default:
swdbReason = libdnf::TransactionItemReason::UNKNOWN;
}

// add item to swdb transaction
_history_write_item(pkg, swdb, swdbAction);
_history_write_item(pkg, swdb, swdbAction, swdbReason);

/* this section done */
ret = dnf_state_done(state_local, error);
Expand Down Expand Up @@ -1277,7 +1290,7 @@ dnf_transaction_commit(DnfTransaction *transaction, HyGoal goal, DnfState *state
swdbAction = libdnf::TransactionItemAction::DOWNGRADED;
}
}
_history_write_item(pkg, swdb, swdbAction);
_history_write_item(pkg, swdb, swdbAction, libdnf::TransactionItemReason::UNKNOWN);
}

/* add anything that gets obsoleted to a helper array which is used to
Expand Down Expand Up @@ -1329,7 +1342,7 @@ dnf_transaction_commit(DnfTransaction *transaction, HyGoal goal, DnfState *state
}

// TODO SWDB add pkg_tmp replaced_by pkg
_history_write_item(pkg_tmp, swdb, swdbAction);
_history_write_item(pkg_tmp, swdb, swdbAction, libdnf::TransactionItemReason::UNKNOWN);
}
g_ptr_array_unref(pkglist);
}
Expand Down

0 comments on commit b2cdd7c

Please sign in to comment.