From 4dc2cf71729b07321e1b2143652fa364ddc6e64f Mon Sep 17 00:00:00 2001
From: Ivo De Decker <ivodd@debian.org>
Date: Mon, 17 Dec 2018 20:53:17 +0000
Subject: [PATCH] Try to remove old libs during hint run

Attempt the removal of the old libraries from smooth updates during every hint
run. In some cases, the removal needs to happen during the hint run for the
hint to succeed.

Signed-off-by: Ivo De Decker <ivodd@debian.org>
---
 britney.py | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/britney.py b/britney.py
index 6a410f9..72fc60d 100755
--- a/britney.py
+++ b/britney.py
@@ -1888,7 +1888,7 @@ class Britney(object):
 
         return (is_accepted, nuninst_after, arch)
 
-    def iter_packages(self, packages, selected, nuninst=None, parent_transaction=None):
+    def iter_packages(self, packages, selected, nuninst=None, parent_transaction=None, try_removals=True):
         """Iter on the list of actions and apply them one-by-one
 
         This method applies the changes from `packages` to testing, checking the uninstallability
@@ -1989,6 +1989,18 @@ class Britney(object):
                         else:
                             maybe_rescheduled_packages.append(comp[0])
 
+        if try_removals and self.options.smooth_updates:
+            self.logger.info("> Removing old packages left in the target suite from smooth updates")
+            removals = old_libraries(self.suite_info, self.options.outofsync_arches)
+            if removals:
+                output_logger.info("Removing packages left in the target suite for smooth updates (%d):", len(removals))
+                log_and_format_old_libraries(self.output_logger, removals)
+                (nuninst_last_accepted, extra) = self.iter_packages(removals,
+                                                                    selected,
+                                                                    nuninst=nuninst_last_accepted,
+                                                                    parent_transaction=parent_transaction,
+                                                                    try_removals=False)
+
         output_logger.info(" finish: [%s]", ",".join(x.uvname for x in selected))
         output_logger.info("endloop: %s", self.eval_nuninst(self.nuninst_orig))
         output_logger.info("    now: %s", self.eval_nuninst(nuninst_last_accepted))