ignore already applied glsas when loading the security set
authorMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 08:13:53 +0000 (08:13 -0000)
committerMarius Mauch <genone@gentoo.org>
Mon, 16 Jul 2007 08:13:53 +0000 (08:13 -0000)
svn path=/main/trunk/; revision=7275

pym/portage/glsa.py
pym/portage/sets/__init__.py
pym/portage/sets/security.py

index ee6343640e1ebba6ee88b91bd7592913b99c53a3..d8053a8204bafc0b796120a1451abd1a162adf6e 100644 (file)
@@ -556,7 +556,7 @@ class Glsa:
                @rtype:         Boolean
                @returns:       True if the GLSA was applied, False if not
                """
-               aList = grabfile(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep)))
+               aList = grabfile(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"))
                return (self.nr in aList)
 
        def inject(self):
@@ -569,7 +569,7 @@ class Glsa:
                @returns:       None
                """
                if not self.isApplied():
-                       checkfile = open(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep)), "a+")
+                       checkfile = open(os.path.join(os.sep, self.config["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa"), "a+")
                        checkfile.write(self.nr+"\n")
                        checkfile.close()
                return None
index d355823cd68cdfba49644f765e8c872ac2405a45..ceebab5a219adef4fc7ce87dda775f9553a9beff 100644 (file)
@@ -103,7 +103,7 @@ def make_default_sets(configroot, root, profile_paths, settings=None,
                vdbapi=None, portdbapi=None):
        from portage.sets.files import StaticFileSet, ConfigFileSet
        from portage.sets.profiles import PackagesSystemSet
-       from portage.sets.security import AffectedSet
+       from portage.sets.security import NewAffectedSet
        from portage.sets.dbapi import EverythingSet
        
        rValue = set()
@@ -114,7 +114,7 @@ def make_default_sets(configroot, root, profile_paths, settings=None,
                rValue.add(myset)
        rValue.add(PackagesSystemSet("system", profile_paths))
        if settings != None and portdbapi != None:
-               rValue.add(AffectedSet("security", settings, vdbapi, portdbapi))
+               rValue.add(NewAffectedSet("security", settings, vdbapi, portdbapi))
        else:
                rValue.add(InternalPackageSet("security"))
        if vdbapi != None:
index 4827886a86f49b822c0004397e2572f9e0150b50..cf4af09408d4c5b1cf59f825491eb457506c8831 100644 (file)
@@ -3,20 +3,34 @@
 # $Id$
 
 import portage.glsa as glsa
+from portage.util import grabfile
+from portage.const import CACHE_PATH
+import os
 
 from portage.sets import PackageSet
 
 class SecuritySet(PackageSet):
        _operations = ["merge"]
-
+       _skip_applied = False
+       
        def __init__(self, name, settings, vardbapi, portdbapi):
                super(SecuritySet, self).__init__(name)
                self._settings = settings
                self._vardbapi = vardbapi
                self._portdbapi = portdbapi
+               self._checkfile = os.path.join(os.sep, self._settings["ROOT"], CACHE_PATH.lstrip(os.sep), "glsa")
+
+       def getGlsaList(self, skip_applied):
+               glsaindexlist = glsa.get_glsa_list(self._settings)
+               if skip_applied:
+                       applied_list = grabfile(self._checkfile)
+                       glsaindexlist = set(glsaindexlist).difference(applied_list)
+                       glsaindexlist = list(glsaindexlist)
+               glsaindexlist.sort()
+               return glsaindexlist
                
        def load(self):
-               glsaindexlist = glsa.get_glsa_list(self._settings)
+               glsaindexlist = self.getGlsaList(self._skip_applied)
                atomlist = []
                for glsaid in glsaindexlist:
                        myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi)
@@ -27,11 +41,22 @@ class SecuritySet(PackageSet):
        
        def useGlsa(self, myglsa):
                return True
+
+       def updateAppliedList(self):
+               glsaindexlist = self.getGlsaList(True)
+               applied_list = grabfile(self._checkfile)
+               for glsaid in glsaindexlist:
+                       myglsa = glsa.Glsa(glsaid, self._settings, self._vardbapi, self._portdbapi)
+                       if not myglsa.isVulnerable():
+                               applied_list.append(glsaid)
+               write_atomic(self._checkfile, "\n".join(applied_list))
        
 class NewGlsaSet(SecuritySet):
-       def useGlsa(self, myglsa):
-               return not myglsa.isApplied()
+       _skip_applied = True
 
 class AffectedSet(SecuritySet):
        def useGlsa(self, myglsa):
                return myglsa.isVulnerable()
+
+class NewAffectedSet(AffectedSet):
+       _skip_applied = True