Hi,

Here's a cleaner version of my patch.

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 15:05:13.893261893 -0700
+++ b/yum/__init__.py   2011-03-21 15:08:35.599242414 -0700
@@ -5185,6 +5185,11 @@
         found_leaves = set()
         checked = set()
         beingremoved = [ t.po for t in 
self.tsInfo.getMembersWithState(output_states=TS_REMOVE_STATES) ]
+        # cache previously examined packages
+        okay_to_remove = {}
+        for i in self.rpmdb.returnPackages():
+            okay_to_remove[i] = True
+
         for pkg in beingremoved: # for each package required by the pkg being 
removed
             #print 'removal: %s' % pkg.name
             for required in pkg.required_packages():
@@ -5192,23 +5197,29 @@
                 #    continue # if we've already checked it, skip it.
                 #checked.add(required)
                 if required.yumdb_info.get('reason', '') != 'dep': # if the 
required pkg is not a dep, then skip it
+                    okay_to_remove[required] = False
                     continue
                 if required in beingremoved:
                     continue
+                if self._has_needed_revdeps(required, beingremoved, 
okay_to_remove):
+                    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():
                         still_needed = True
+                        okay_to_remove[required] = False
                         break
                 for fn in required.filelist + required.dirlist:
                     if self.tsInfo.getNewRequires(fn, 
None,(None,None,None)).keys():
+                        okay_to_remove[required] = False
                         still_needed = True
                         break
                             
@@ -5228,5 +5239,53 @@
                             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, ok_to_remove):
+        # check if we've already found this package to have user-installed deps
+        if not ok_to_remove[pkg]:
+            # Debugging output
+            #print pkg, "has been visited already and cannot be removed!!!"
+            return True
+        # 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 not ok_to_remove[curpkg]:
+                    # Debugging
+                    #print pkg, "has been visited already and cannot be 
removed!!!"
+                    ok_to_remove[pkg] = False
+                    return True
+                if curpkg.yumdb_info.get('reason', '') != 'dep':
+                    # Debugging output
+                    #print pkg, "has revdep", curpkg, "which was 
user-installed."
+                    ok_to_remove[pkg] = False
+                    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