Blame SOURCES/0033-libdnf-transaction-RPMItem-Fix-handling-transaction-.patch

2c1f71
From c5919efe898294420ec8e91e4eed5b9081e681c5 Mon Sep 17 00:00:00 2001
2c1f71
From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hr=C3=A1zk=C3=BD?= <lhrazky@redhat.com>
2c1f71
Date: Thu, 17 Feb 2022 18:18:16 +0100
2c1f71
Subject: [PATCH 33/34] libdnf/transaction/RPMItem: Fix handling transaction id
2c1f71
 in resolveTransactionItemReason
2c1f71
2c1f71
The maxTransactionId argument was ignored, the method was always returning the
2c1f71
reason from the last transaction. This is the correct result for
2c1f71
maxTransactionId = -1. In a couple of places the method is called with
2c1f71
maxTransactionId = -2. Fixing this would mean nontrivial changes to the
2c1f71
logic which could potentially break something else, so I'm leaving this
2c1f71
behavior unchanged.
2c1f71
2c1f71
For non-negative values of maxTransactionId (with which it's not being called
2c1f71
anywhere in dnf codebase), the commit adds a condition to SELECT only
2c1f71
transaction ids less than or equal to maxTransactionId.
2c1f71
2c1f71
= changelog =
2c1f71
msg: Fix handling transaction id in resolveTransactionItemReason
2c1f71
type: bugfix
2c1f71
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2053014
2c1f71
resolves: https://bugzilla.redhat.com/show_bug.cgi?id=2010259
2c1f71
---
2c1f71
 libdnf/transaction/RPMItem.cpp | 21 ++++++++++++++++++---
2c1f71
 1 file changed, 18 insertions(+), 3 deletions(-)
2c1f71
2c1f71
diff --git a/libdnf/transaction/RPMItem.cpp b/libdnf/transaction/RPMItem.cpp
2c1f71
index 5f667ab9..ecce789d 100644
2c1f71
--- a/libdnf/transaction/RPMItem.cpp
2c1f71
+++ b/libdnf/transaction/RPMItem.cpp
2c1f71
@@ -255,7 +255,11 @@ RPMItem::resolveTransactionItemReason(SQLite3Ptr conn,
2c1f71
                                       const std::string &arch,
2c1f71
                                       int64_t maxTransactionId)
2c1f71
 {
2c1f71
-    const char *sql = R"**(
2c1f71
+    // NOTE: All negative maxTransactionId values are treated the same. The
2c1f71
+    // method is called with maxTransactionId = -2 in a couple of places, the
2c1f71
+    // semantics here have been the same as with -1 for a long time. If it
2c1f71
+    // ain't broke...
2c1f71
+    std::string sql = R"**(
2c1f71
         SELECT
2c1f71
             ti.action as action,
2c1f71
             ti.reason as reason
2c1f71
@@ -271,14 +275,25 @@ RPMItem::resolveTransactionItemReason(SQLite3Ptr conn,
2c1f71
             AND ti.action not in (3, 5, 7, 10)
2c1f71
             AND i.name = ?
2c1f71
             AND i.arch = ?
2c1f71
+    )**";
2c1f71
+
2c1f71
+    if (maxTransactionId >= 0) {
2c1f71
+        sql.append(" AND ti.trans_id <= ?");
2c1f71
+    }
2c1f71
+
2c1f71
+    sql.append(R"**(
2c1f71
         ORDER BY
2c1f71
             ti.trans_id DESC
2c1f71
         LIMIT 1
2c1f71
-    )**";
2c1f71
+    )**");
2c1f71
 
2c1f71
     if (arch != "") {
2c1f71
         SQLite3::Query query(*conn, sql);
2c1f71
-        query.bindv(name, arch);
2c1f71
+        if (maxTransactionId >= 0) {
2c1f71
+            query.bindv(name, arch, maxTransactionId);
2c1f71
+        } else {
2c1f71
+            query.bindv(name, arch);
2c1f71
+        }
2c1f71
 
2c1f71
         if (query.step() == SQLite3::Statement::StepResult::ROW) {
2c1f71
             auto action = static_cast< TransactionItemAction >(query.get< int64_t >("action"));
2c1f71
-- 
2c1f71
2.31.1
2c1f71