Blame SOURCES/0004-Print-info-about-obsoleted-packages-before-transaction-RhBug-1855542.patch

c4d784
From 9224bd0556c5b056ae6250d8aa582dfdcc2de650 Mon Sep 17 00:00:00 2001
c4d784
From: Jaroslav Rohel <jrohel@redhat.com>
c4d784
Date: Mon, 13 Jul 2020 22:17:10 +0200
c4d784
Subject: [PATCH] Print info about obsoleted packages before transaction
c4d784
 (RhBug:1855542)
c4d784
MIME-Version: 1.0
c4d784
Content-Type: text/plain; charset=UTF-8
c4d784
Content-Transfer-Encoding: 8bit
c4d784
c4d784
- Added number of obsolete packages into transaction summary.
c4d784
- Added which packages are obsolete and by whom they are replaced.
c4d784
c4d784
The user can run microdnf in test mode (--setopt=tsflags=test) to know
c4d784
what microdnf will do. However, without this patch, information about
c4d784
obsolete (replaced as obsolete) packages was missing.
c4d784
c4d784
Example output before patch:
c4d784
# microdnf install TestB
c4d784
Package                                           Repository        Size
c4d784
Installing:
c4d784
 TestB-1.0.0-1.noarch                             ci-obsoletes    5,9 kB
c4d784
Transaction Summary:
c4d784
 Installing:        1 packages
c4d784
 Reinstalling:      0 packages
c4d784
 Upgrading:         0 packages
c4d784
 Removing:          0 packages
c4d784
 Downgrading:       0 packages
c4d784
Downloading packages...
c4d784
Running transaction test...
c4d784
Installing: TestB;1.0.0-1;noarch;ci-obsoletes
c4d784
Obsoleting: TestA;1.0.0-1;noarch;installed
c4d784
Complete.
c4d784
c4d784
Example output after patch:
c4d784
# microdnf install TestB
c4d784
Package                                           Repository        Size
c4d784
Installing:
c4d784
 TestB-1.0.0-1.noarch                             ci-obsoletes    5,9 kB
c4d784
   replacing TestA-1.0.0-1.noarch
c4d784
Transaction Summary:
c4d784
 Installing:        1 packages
c4d784
 Reinstalling:      0 packages
c4d784
 Upgrading:         0 packages
c4d784
 Obsoleting:        1 packages
c4d784
 Removing:          0 packages
c4d784
 Downgrading:       0 packages
c4d784
Downloading packages...
c4d784
Running transaction test...
c4d784
Installing: TestB;1.0.0-1;noarch;ci-obsoletes
c4d784
Obsoleting: TestA;1.0.0-1;noarch;installed
c4d784
Complete.
c4d784
---
c4d784
 dnf/dnf-utils.c | 37 ++++++++++++++++++++++++++++---------
c4d784
 1 file changed, 28 insertions(+), 9 deletions(-)
c4d784
c4d784
diff --git a/dnf/dnf-utils.c b/dnf/dnf-utils.c
c4d784
index c58f519..ff0e891 100644
c4d784
--- a/dnf/dnf-utils.c
c4d784
+++ b/dnf/dnf-utils.c
c4d784
@@ -3,6 +3,7 @@
c4d784
  * Copyright © 2010-2015 Richard Hughes <richard@hughsie.com>
c4d784
  * Copyright © 2016 Colin Walters <walters@verbum.org>
c4d784
  * Copyright © 2016-2017 Igor Gnatenko <ignatenko@redhat.com>
c4d784
+ * Copyright © 2017-2020 Jaroslav Rohel <jrohel@redhat.com>
c4d784
  *
c4d784
  * This program is free software: you can redistribute it and/or modify
c4d784
  * it under the terms of the GNU General Public License as published by
c4d784
@@ -34,13 +35,15 @@ dnf_package_cmp_cb (DnfPackage **pkg1, DnfPackage **pkg2)
c4d784
 
c4d784
 
c4d784
 static void
c4d784
-dnf_utils_add_transaction_packages (struct libscols_table *tb,
c4d784
+dnf_utils_add_transaction_packages (DnfContext *ctx,
c4d784
+                                    struct libscols_table *tb,
c4d784
                                     struct libscols_line *parent,
c4d784
                                     GPtrArray *pkgs)
c4d784
 {
c4d784
   // sort packages by NEVRA
c4d784
   g_ptr_array_sort (pkgs, (GCompareFunc) dnf_package_cmp_cb);
c4d784
 
c4d784
+  HyGoal goal = dnf_context_get_goal (ctx);
c4d784
   for (guint i = 0; i < pkgs->len; i++)
c4d784
     {
c4d784
       DnfPackage *pkg = pkgs->pdata[i];
c4d784
@@ -48,9 +51,21 @@ dnf_utils_add_transaction_packages (struct libscols_table *tb,
c4d784
       struct libscols_line *ln = scols_table_new_line (tb, parent);
c4d784
       scols_line_set_data (ln, COL_NEVRA, dnf_package_get_nevra (pkg));
c4d784
       scols_line_set_data (ln, COL_REPO, dnf_package_get_reponame (pkg));
c4d784
-      char *formatted_pkg_size = g_format_size (dnf_package_get_size (pkg));
c4d784
+      g_autofree gchar *formatted_pkg_size = g_format_size (dnf_package_get_size (pkg));
c4d784
       scols_line_set_data (ln, COL_SIZE, formatted_pkg_size);
c4d784
-      g_free(formatted_pkg_size);
c4d784
+
c4d784
+      if (dnf_package_get_action (pkg) != DNF_STATE_ACTION_REMOVE)
c4d784
+        {
c4d784
+          g_autoptr(GPtrArray) pkgs_replaced = hy_goal_list_obsoleted_by_package (goal, pkg);
c4d784
+          g_ptr_array_sort (pkgs_replaced, (GCompareFunc) dnf_package_cmp_cb);
c4d784
+          for (guint i = 0; i < pkgs_replaced->len; i++)
c4d784
+            {
c4d784
+              DnfPackage *pkg = pkgs_replaced->pdata[i];
c4d784
+              struct libscols_line *replacing_ln = scols_table_new_line (tb, ln);
c4d784
+              g_autofree gchar *replacing_text = g_strconcat ("replacing ", dnf_package_get_nevra (pkg), NULL);
c4d784
+              scols_line_set_data (replacing_ln, COL_NEVRA, replacing_text);
c4d784
+            }
c4d784
+        }
c4d784
     }
c4d784
 }
c4d784
 
c4d784
@@ -92,10 +107,9 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
     {
c4d784
       ln = scols_table_new_line (tb, NULL);
c4d784
       scols_line_set_data (ln, COL_NEVRA, "Installing:");
c4d784
-      dnf_utils_add_transaction_packages (tb, ln, pkgs_install);
c4d784
+      dnf_utils_add_transaction_packages (ctx, tb, ln, pkgs_install);
c4d784
     }
c4d784
 
c4d784
-
c4d784
   g_autoptr(GPtrArray) pkgs_reinstall = dnf_goal_get_packages (dnf_context_get_goal (ctx),
c4d784
                                                                DNF_PACKAGE_INFO_REINSTALL,
c4d784
                                                                -1);
c4d784
@@ -103,7 +117,7 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
     {
c4d784
       ln = scols_table_new_line (tb, NULL);
c4d784
       scols_line_set_data (ln, COL_NEVRA, "Reinstalling:");
c4d784
-      dnf_utils_add_transaction_packages (tb, ln, pkgs_reinstall);
c4d784
+      dnf_utils_add_transaction_packages (ctx, tb, ln, pkgs_reinstall);
c4d784
     }
c4d784
 
c4d784
   g_autoptr(GPtrArray) pkgs_upgrade = dnf_goal_get_packages (dnf_context_get_goal (ctx),
c4d784
@@ -113,9 +127,13 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
     {
c4d784
       ln = scols_table_new_line (tb, NULL);
c4d784
       scols_line_set_data (ln, COL_NEVRA, "Upgrading:");
c4d784
-      dnf_utils_add_transaction_packages (tb, ln, pkgs_upgrade);
c4d784
+      dnf_utils_add_transaction_packages (ctx, tb, ln, pkgs_upgrade);
c4d784
     }
c4d784
 
c4d784
+  g_autoptr(GPtrArray) pkgs_obsolete = dnf_goal_get_packages (dnf_context_get_goal (ctx),
c4d784
+                                                             DNF_PACKAGE_INFO_OBSOLETE,
c4d784
+                                                             -1);
c4d784
+
c4d784
   g_autoptr(GPtrArray) pkgs_remove = dnf_goal_get_packages (dnf_context_get_goal (ctx),
c4d784
                                                             DNF_PACKAGE_INFO_REMOVE,
c4d784
                                                             -1);
c4d784
@@ -123,7 +141,7 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
     {
c4d784
       ln = scols_table_new_line (tb, NULL);
c4d784
       scols_line_set_data (ln, COL_NEVRA, "Removing:");
c4d784
-      dnf_utils_add_transaction_packages (tb, ln, pkgs_remove);
c4d784
+      dnf_utils_add_transaction_packages (ctx, tb, ln, pkgs_remove);
c4d784
     }
c4d784
 
c4d784
   g_autoptr(GPtrArray) pkgs_downgrade = dnf_goal_get_packages (dnf_context_get_goal (ctx),
c4d784
@@ -133,7 +151,7 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
     {
c4d784
       ln = scols_table_new_line (tb, NULL);
c4d784
       scols_line_set_data (ln, COL_NEVRA, "Downgrading:");
c4d784
-      dnf_utils_add_transaction_packages (tb, ln, pkgs_downgrade);
c4d784
+      dnf_utils_add_transaction_packages (ctx, tb, ln, pkgs_downgrade);
c4d784
     }
c4d784
 
c4d784
   scols_print_table (tb);
c4d784
@@ -144,6 +162,7 @@ dnf_utils_print_transaction (DnfContext *ctx)
c4d784
   g_print (" %-15s %4d packages\n", "Installing:", pkgs_install->len);
c4d784
   g_print (" %-15s %4d packages\n", "Reinstalling:", pkgs_reinstall->len);
c4d784
   g_print (" %-15s %4d packages\n", "Upgrading:", pkgs_upgrade->len);
c4d784
+  g_print (" %-15s %4d packages\n", "Obsoleting:", pkgs_obsolete->len);
c4d784
   g_print (" %-15s %4d packages\n", "Removing:", pkgs_remove->len);
c4d784
   g_print (" %-15s %4d packages\n", "Downgrading:", pkgs_downgrade->len);
c4d784