Fix depclean so that it cleans unneeded slots (unless they are exempted by the system...
authorZac Medico <zmedico@gentoo.org>
Mon, 31 Jul 2006 18:10:19 +0000 (18:10 -0000)
committerZac Medico <zmedico@gentoo.org>
Mon, 31 Jul 2006 18:10:19 +0000 (18:10 -0000)
svn path=/main/branches/2.1/; revision=4066

bin/emerge

index eafc07810fcd46609c05ea3eb66c00811f3be492..1b5de9765d9631b525450b32bb0a5a82e76d0fbc 100755 (executable)
@@ -22,6 +22,9 @@ import portage_locks
 import portage_exception
 from portage_const import PROFILE_PATH
 
+if not hasattr(__builtins__, "set"):
+       from sets import Set as set
+
 portage.global_updates(
        portage.settings, portage.db, portage.mtimedb["updates"])
 
@@ -3275,9 +3278,10 @@ elif "depclean"==myaction:
        print red("*** WARNING ***")
        print red("*** WARNING ***")+"  "+bold("Make sure you have a backup.")
 
+       vartree = portage.db[portage.settings["ROOT"]]["vartree"]
        syslist=getlist("system")
        worldlist=getlist("world")
-       myvarlist=portage.vardbapi(portage.root).cp_all()
+       myvarlist = vartree.dbapi.cpv_all()
 
        if not syslist:
                print "\n!!! You have no system list.",
@@ -3317,6 +3321,7 @@ elif "depclean"==myaction:
                sys.exit(1)
 
        reallist=[]
+       explicitly_required = set()
        for x in alldeps:
                myparts=portage.catpkgsplit(string.split(x)[2])
                if not myparts:
@@ -3332,31 +3337,23 @@ elif "depclean"==myaction:
                catpack=myparts[0]+"/"+myparts[1]
                if catpack not in reallist:
                        reallist.append(catpack)
+               explicitly_required.add(x.split()[2])
+
+       
+       sys_world_unversioned = set()
+       from itertools import chain
+       for x in chain(syslist, worldlist):
+               sys_world_unversioned.add(portage.dep_getkey(x))
 
        cleanlist=[]
        for x in myvarlist:
-               if x not in reallist:
-                       if x not in cleanlist:
+               if x not in explicitly_required:
+                       # We have to exempt all slots from the system and world sets since
+                       # there's currently no way of knowing which slots the user may want
+                       # to keep.
+                       if portage.dep_getkey(x) not in sys_world_unversioned:
                                cleanlist.append(x)
 
-       for x in syslist+worldlist:
-               myparts = portage.catpkgsplit(x)
-               if myparts:
-                       if myparts[0][0] in ('<','>','='):
-                               myparts[0] = myparts[0][1:]
-                       if myparts[0][0] in ('<','>','='):
-                               myparts[0] = myparts[0][1:]
-                       catpack=myparts[0]+"/"+myparts[1]
-               else:
-                       catpack=x
-               if catpack in cleanlist:
-                       cleanlist.remove(catpack)
-
-       #print "\n\n\nCleaning: "
-       #for x in cleanlist:
-       #       print x
-       #print
-
        if len(cleanlist):
                unmerge("unmerge", cleanlist)