Hi,

I have amended _remove_old_deps in __init__.py to deal properly with
chains of unused deps. See attached patch. It's a proof-of-concept, and
any feedback would be appreciated.

Casey

On 03/21/2011 05:43 AM, seth vidal wrote:
> On Sun, 2011-03-20 at 20:47 -0700, Casey Jao wrote:
>> Did your patch make it into 3.2.29? Or should I get it from git?
> 
> 
> 3.2.29 has it, yep.
> 
> -sv
> 
> 
> _______________________________________________
> Yum-devel mailing list
> [email protected]
> http://lists.baseurl.org/mailman/listinfo/yum-devel
--- a/yum/__init__.py   2011-03-21 12:35:08.151947466 -0700
+++ b/yum/__init__.py   2011-03-21 12:39:19.867140199 -0700
@@ -5195,13 +5195,16 @@
                     continue
                 if required in beingremoved:
                     continue
+                if self._has_needed_revdeps(required, beingremoved):
+                    continue
                 still_needed = False
                 for requiring in required.requiring_packages(): # so we have 
required deps - look at all the pkgs which require them
                     if requiring == required: # if they are self-requiring 
skip them
                         continue
-                    if requiring not in beingremoved: # if the requiring pkg 
is not in the list of pkgs being removed then it is still needed
-                        still_needed = True
-                        break
+                    #if requiring not in beingremoved: # if the requiring pkg 
is not in the list of pkgs being removed then it is still needed
+                        #still_needed = True
+                        #break
+                    
                 # go through the stuff in the ts to be installed - make sure 
none of that needs the required pkg, either.
                 for (provn,provf,provevr) in required.provides:
                     if self.tsInfo.getNewRequires(provn, provf, 
provevr).keys():
@@ -5228,5 +5231,42 @@
                             beingremoved.append(txmbr.po)
                         found_leaves.add(txmbr)
         self.verbose_logger.log(logginglevels.INFO_2, "Found and removing %s 
unneeded dependencies" % len(found_leaves))
-        
-                    
+            
+    # Checks if pkg has any reverse deps which cannot be removed. 
+    # Currently this only checks the install reason for each revdep, 
+    # but we may want to check for other reasons that would  
+    # prevent the revdep from being removed (e.g. protected)
+    def _has_needed_revdeps(self, pkg, beingremoved):
+        # Debugging output
+        print "Examining revdeps of", pkg
+        # track which pkgs we have visited already
+        visited = {}
+        for po in self.rpmdb.returnPackages():
+            visited[po] = False
+        # no need to consider packages that are already being removed
+        for po in beingremoved:
+            visited[po] = True
+        stack = []
+        stack.append(pkg)
+        # depth-first search
+        while stack:
+            curpkg = stack[-1]
+            if not visited[curpkg]:
+                if curpkg.yumdb_info.get('reason', '') != 'dep':
+                    # Debugging output
+                    print pkg, "has revdep", curpkg, "which was 
user-installed."
+                    return True
+                visited[curpkg] = True
+            all_leaves_visited = True
+            leaves = curpkg.requiring_packages()
+            for leaf in leaves:
+                if not visited[leaf]:
+                    stack.append(leaf)
+                    all_leaves_visited = False
+                    break
+            if all_leaves_visited:
+                stack.pop()
+        # Debugging output
+        print pkg, "has no user-installed revdeps"
+        return False
+

Attachment: signature.asc
Description: OpenPGP digital signature

_______________________________________________
Yum-devel mailing list
[email protected]
http://lists.baseurl.org/mailman/listinfo/yum-devel

Reply via email to