From: Zac Medico Date: Thu, 27 Jun 2013 19:38:39 +0000 (-0700) Subject: cacheddir: disable cache (avoid memory leak) X-Git-Tag: v2.2.0_alpha186~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0196031ce8f5dc8b9385e06013e42c47d1185a3b;p=portage.git cacheddir: disable cache (avoid memory leak) The global dircache is no longer supported, since it could be a memory leak for API consumers. Any cacheddir callers should use higher-level caches instead, when necessary. --- diff --git a/pym/_emerge/clear_caches.py b/pym/_emerge/clear_caches.py index 7b7c5eced..513df626f 100644 --- a/pym/_emerge/clear_caches.py +++ b/pym/_emerge/clear_caches.py @@ -1,8 +1,7 @@ -# Copyright 1999-2010 Gentoo Foundation +# Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import gc -from portage.util.listdir import dircache def clear_caches(trees): for d in trees.values(): @@ -15,5 +14,4 @@ def clear_caches(trees): pass else: d["vartree"].dbapi._linkmap._clear_cache() - dircache.clear() gc.collect() diff --git a/pym/portage/util/listdir.py b/pym/portage/util/listdir.py index b78ed19fe..61a025ae7 100644 --- a/pym/portage/util/listdir.py +++ b/pym/portage/util/listdir.py @@ -5,32 +5,26 @@ __all__ = ['cacheddir', 'listdir'] import errno import stat -import time from portage import os from portage.const import VCS_DIRS from portage.exception import DirectoryNotFound, PermissionDenied, PortageException -from portage.util import normalize_path, writemsg - +from portage.util import normalize_path + +# The global dircache is no longer supported, since it could +# be a memory leak for API consumers. Any cacheddir callers +# should use higher-level caches instead, when necessary. +# TODO: Remove dircache variable after stable portage does +# not use is (keep it for now, in case API consumers clear +# it manually). dircache = {} -cacheHit = 0 -cacheMiss = 0 -cacheStale = 0 def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymlinks=True): - global cacheHit,cacheMiss,cacheStale mypath = normalize_path(my_original_path) - if mypath in dircache: - cacheHit += 1 - cached_mtime, list, ftype = dircache[mypath] - else: - cacheMiss += 1 - cached_mtime, list, ftype = -1, [], [] + cached_mtime, list, ftype = -1, [], [] try: pathstat = os.stat(mypath) - if stat.S_ISDIR(pathstat[stat.ST_MODE]): - mtime = pathstat.st_mtime - else: + if not stat.S_ISDIR(pathstat.st_mode): raise DirectoryNotFound(mypath) except EnvironmentError as e: if e.errno == PermissionDenied.errno: @@ -39,10 +33,7 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli return [], [] except PortageException: return [], [] - # Python retuns mtime in seconds, so if it was changed in the last few seconds, it could be invalid - if mtime != cached_mtime or time.time() - mtime < 4: - if mypath in dircache: - cacheStale += 1 + else: try: list = os.listdir(mypath) except EnvironmentError as e: @@ -68,7 +59,6 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli ftype.append(3) except (IOError, OSError): ftype.append(3) - dircache[mypath] = mtime, list, ftype ret_list = [] ret_ftype = [] @@ -84,7 +74,6 @@ def cacheddir(my_original_path, ignorecvs, ignorelist, EmptyOnError, followSymli ret_list.append(list[x]) ret_ftype.append(ftype[x]) - writemsg("cacheddirStats: H:%d/M:%d/S:%d\n" % (cacheHit, cacheMiss, cacheStale),10) return ret_list, ret_ftype def listdir(mypath, recursive=False, filesonly=False, ignorecvs=False, ignorelist=[], followSymlinks=True,