From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 36C961381F3 for ; Thu, 27 Jun 2013 19:39:30 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B7E84E07FA; Thu, 27 Jun 2013 19:39:29 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3F94FE07FA for ; Thu, 27 Jun 2013 19:39:29 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 069B133E7B8 for ; Thu, 27 Jun 2013 19:39:28 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 93A82E468F for ; Thu, 27 Jun 2013 19:39:26 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1372361919.0196031ce8f5dc8b9385e06013e42c47d1185a3b.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/util/, pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/clear_caches.py pym/portage/util/listdir.py X-VCS-Directories: pym/portage/util/ pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 0196031ce8f5dc8b9385e06013e42c47d1185a3b X-VCS-Branch: master Date: Thu, 27 Jun 2013 19:39:26 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 93de042d-e517-4da4-b579-b90011b64640 X-Archives-Hash: efeecb31a0ab453d97fab6f0d6e44bc3 commit: 0196031ce8f5dc8b9385e06013e42c47d1185a3b Author: Zac Medico gentoo org> AuthorDate: Thu Jun 27 19:38:39 2013 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Jun 27 19:38:39 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=0196031c 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. --- pym/_emerge/clear_caches.py | 4 +--- pym/portage/util/listdir.py | 33 +++++++++++---------------------- 2 files changed, 12 insertions(+), 25 deletions(-) diff --git a/pym/_emerge/clear_caches.py b/pym/_emerge/clear_caches.py index 7b7c5ec..513df62 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 b78ed19..61a025a 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,