Add vardbapi.aux_get() support for an "_mtime_" value which corresponds to
authorZac Medico <zmedico@gentoo.org>
Thu, 5 Jun 2008 17:30:46 +0000 (17:30 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 5 Jun 2008 17:30:46 +0000 (17:30 -0000)
the installed package directory's mtime (numeric value from stat result).
This value can be used to validate indexes or caches used in the optimization
of vdb query operations for various types of package metadata such as
dependencies and file contents.

svn path=/main/trunk/; revision=10586

pym/portage/dbapi/vartree.py

index d931c5ddf22d1c84272bbb96be03b121299787cd..cb2fe28ba4f7cb533aa58f2d289b76d8c1a35fdb 100644 (file)
@@ -632,7 +632,7 @@ class vardbapi(dbapi):
                mydir_mtime = long(mydir_stat.st_mtime)
                pkg_data = self._aux_cache["packages"].get(mycpv)
                pull_me = cache_these.union(wants)
-               mydata = {}
+               mydata = {"_mtime_" : mydir_mtime}
                cache_valid = False
                cache_incomplete = False
                cache_mtime = None
@@ -656,7 +656,8 @@ class vardbapi(dbapi):
                if pull_me:
                        # pull any needed data and cache it
                        aux_keys = list(pull_me)
-                       for k, v in izip(aux_keys, self._aux_get(mycpv, aux_keys)):
+                       for k, v in izip(aux_keys,
+                               self._aux_get(mycpv, aux_keys, st=mydir_stat)):
                                mydata[k] = v
                        if not cache_valid or cache_these.difference(metadata):
                                cache_data = {}
@@ -668,18 +669,25 @@ class vardbapi(dbapi):
                                self._aux_cache["modified"].add(mycpv)
                return [mydata[x] for x in wants]
 
-       def _aux_get(self, mycpv, wants):
+       def _aux_get(self, mycpv, wants, st=None):
                mydir = self.getpath(mycpv)
-               try:
-                       if not stat.S_ISDIR(os.stat(mydir).st_mode):
-                               raise KeyError(mycpv)
-               except OSError, e:
-                       if e.errno == errno.ENOENT:
-                               raise KeyError(mycpv)
-                       del e
-                       raise
+               if st is None:
+                       try:
+                               st = os.stat(mydir)
+                       except OSError, e:
+                               if e.errno == errno.ENOENT:
+                                       raise KeyError(mycpv)
+                               elif e.errno == PermissionDenied.errno:
+                                       raise PermissionDenied(mydir)
+                               else:
+                                       raise
+               if not stat.S_ISDIR(st.st_mode):
+                       raise KeyError(mycpv)
                results = []
                for x in wants:
+                       if x == "_mtime_":
+                               results.append(st.st_mtime)
+                               continue
                        try:
                                myf = open(os.path.join(mydir, x), "r")
                                try: