From: Zac Medico Date: Mon, 16 Jun 2008 11:30:39 +0000 (-0000) Subject: Bug #223417 - Due to 1 second mtime granularity in < python-1.5, mtime checks X-Git-Tag: v2.1.5.6~15 X-Git-Url: http://git.tremily.us/gitweb.cgi?a=commitdiff_plain;h=4a0fa6a7a3e203aef40f45f0e380b5b1034d016c;p=portage.git Bug #223417 - Due to 1 second mtime granularity in < python-1.5, mtime checks are not always sufficient to invalidate vardbapi caches. Therefore, the caches need to be actively invalidated when packages are added and removed. (trunk r10660) svn path=/main/branches/2.1.2/; revision=10667 --- diff --git a/pym/portage.py b/pym/portage.py index fbd997692..1f41ef867 100644 --- a/pym/portage.py +++ b/pym/portage.py @@ -6551,6 +6551,22 @@ class dbapi(object): 'return: ["0",">=sys-libs/bar-1.0","http://www.foo.com"] or [] if mycpv not found' raise NotImplementedError + def _add(self, pkg_dblink): + self._clear_cache(pkg_dblink) + + def _remove(self, pkg_dblink): + self._clear_cache(pkg_dblink) + + def _clear_cache(self, pkg_dblink): + # Due to 1 second mtime granularity in < python-1.5, mtime checks + # are not always sufficient to invalidate vardbapi caches. Therefore, + # the caches need to be actively invalidated here. + self.mtdircache.pop(pkg_dblink.cat, None) + self.matchcache.pop(pkg_dblink.cat, None) + self.cpcache.pop(pkg_dblink.mysplit[0], None) + from portage import dircache + dircache.pop(pkg_dblink.dbcatdir, None) + def match(self, origdep, use_cache=1): """Given a dependency, try to find packages that match Args: @@ -9033,24 +9049,15 @@ class dblink: """ if not os.path.exists(self.dbdir): return - try: - for x in os.listdir(self.dbdir): - os.unlink(self.dbdir+"/"+x) - os.rmdir(self.dbdir) - except OSError, e: - print "!!! Unable to remove db entry for this package." - print "!!! It is possible that a directory is in this one. Portage will still" - print "!!! register this package as installed as long as this directory exists." - print "!!! You may delete this directory with 'rm -Rf "+self.dbdir+"'" - print "!!! "+str(e) - print - sys.exit(1) - # Due to mtime granularity, mtime checks do not always properly - # invalidate vardbapi caches. - self.vartree.dbapi.mtdircache.pop(self.cat, None) - self.vartree.dbapi.matchcache.pop(self.cat, None) - self.vartree.dbapi.cpcache.pop(self.mysplit[0], None) + # Check validity of self.dbdir before attempting to remove it. + if not self.dbdir.startswith(self.dbroot): + writemsg("portage.dblink.delete(): invalid dbdir: %s\n" % \ + self.dbdir, noiselevel=-1) + return + import shutil + shutil.rmtree(self.dbdir) + self.vartree.dbapi._remove(self) def clearcontents(self): """ @@ -10206,11 +10213,7 @@ class dblink: f.write(line) f.close() - # Due to mtime granularity, mtime checks do not always properly - # invalidate vardbapi caches. - self.vartree.dbapi.mtdircache.pop(self.cat, None) - self.vartree.dbapi.matchcache.pop(self.cat, None) - self.vartree.dbapi.cpcache.pop(self.mysplit[0], None) + self.vartree.dbapi._add(self) contents = self.getcontents() #do postinst script