Attached is a patch to add a --removenewestdupes command to the --cleandupes
commands.

Currently --cleandupes will always try to remove the newest of each duplicate,
but this is not always possible - sometimes you must remove the newest. This
trivial patch makes that possible.

-- 
Phil Dibowitz                             p...@ipom.com
Open Source software and tech docs        Insanity Palace of Metallica
http://www.phildev.net/                   http://www.ipom.com/

"Be who you are and say what you feel, because those who mind don't matter
 and those who matter don't mind."
 - Dr. Seuss

commit f2a9cce06001d3a7264736751e1c50a50f589cc4
Author: Phil Dibowitz <p...@ipom.com>
Date:   7 days ago

    Add option to remove newest dupes instead of oldest dupes
    
    Sometimes in a failed transaction you need to remove the newest of the dupes and
    not the oldest. This provides that option.

diff --git a/package-cleanup.py b/package-cleanup.py
index acad9f2..13cfb89 100755
--- a/package-cleanup.py
+++ b/package-cleanup.py
@@ -79,6 +79,9 @@ class PackageCleanup(YumUtilBase):
         dupegrp.add_option("--cleandupes", default=False, 
                     dest="cleandupes", action="store_true",
                     help='Scan for duplicates in your rpmdb and remove older ')
+        dupegrp.add_option("--removenewestdupes", default=False, 
+                    dest="removenewestdupes", action="store_true",
+                    help='Remove the newest dupes instead of the oldest dupes.')
         dupegrp.add_option("--noscripts", default=False,
                     dest="noscripts", action="store_true",
                     help="disable rpm scriptlets from running when cleaning duplicates")
@@ -172,7 +175,7 @@ class PackageCleanup(YumUtilBase):
             
         return results
 
-    def _remove_old_dupes(self):
+    def _remove_dupes(self, newest=False):
         """add older duplicate pkgs to be removed in the transaction"""
         dupedict = self._find_installed_duplicates()
 
@@ -180,7 +183,11 @@ class PackageCleanup(YumUtilBase):
         for (name,dupelists) in dupedict.items():
             for dupelist in dupelists:
                 dupelist.sort()
-                for lowpo in dupelist[0:-1]:
+                if newest:
+                    plist = dupelist[1:]
+                else:
+                    plist = dupelist[0:-1]
+                for lowpo in plist:
                     removedupes.append(lowpo)
 
         for po in removedupes:
@@ -373,7 +380,7 @@ class PackageCleanup(YumUtilBase):
                 sys.exit(1)
             if opts.noscripts:
                 self.conf.tsflags.append('noscripts')
-            self._remove_old_dupes()
+            self._remove_dupes(opts.removenewestdupes)
             self.run_with_package_names.add('yum-utils')
 
             if hasattr(self, 'doUtilBuildTransaction'):

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Yum-devel mailing list
Yum-devel@lists.baseurl.org
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to