dcavalca / rpms / libdnf

Forked from rpms/libdnf 2 years ago
Clone

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

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