From: Moshe Zadka Date: Sat, 31 Mar 2001 13:46:34 +0000 (+0000) Subject: - #130306 - statcache.py - full of thread problems. X-Git-Tag: v2.0.1c1~30 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=98cf19babe16df35c4a88603b0fc012b720e909e;p=thirdparty%2FPython%2Fcpython.git - #130306 - statcache.py - full of thread problems. - Made statcache.forget_dir more portable --- diff --git a/Lib/statcache.py b/Lib/statcache.py index b5147c233dc5..7eb87b96a969 100644 --- a/Lib/statcache.py +++ b/Lib/statcache.py @@ -14,22 +14,24 @@ cache = {} def stat(path): """Stat a file, possibly out of the cache.""" - if cache.has_key(path): - return cache[path] + ret = cache.get(path, None) + if ret is not None: + return ret cache[path] = ret = os.stat(path) return ret def reset(): """Reset the cache completely.""" - global cache - cache = {} + cache.clear() def forget(path): """Remove a given item from the cache, if it exists.""" - if cache.has_key(path): + try: del cache[path] + except KeyError: + pass def forget_prefix(prefix): @@ -37,25 +39,18 @@ def forget_prefix(prefix): n = len(prefix) for path in cache.keys(): if path[:n] == prefix: - del cache[path] + forget(path) def forget_dir(prefix): """Forget about a directory and all entries in it, but not about entries in subdirectories.""" - if prefix[-1:] == '/' and prefix <> '/': - prefix = prefix[:-1] + import os.path + prefix = os.path.dirname(os.path.join(prefix, "xxx")) forget(prefix) - if prefix[-1:] <> '/': - prefix = prefix + '/' - n = len(prefix) for path in cache.keys(): - if path[:n] == prefix: - rest = path[n:] - if rest[-1:] == '/': rest = rest[:-1] - if '/' not in rest: - del cache[path] - + if path.startswith(prefix) and os.path.dirname(path) == prefix: + forget(path) def forget_except_prefix(prefix): """Remove all pathnames except with a given prefix. @@ -63,7 +58,7 @@ def forget_except_prefix(prefix): n = len(prefix) for path in cache.keys(): if path[:n] <> prefix: - del cache[path] + forget(path) def isdir(path): diff --git a/Misc/NEWS b/Misc/NEWS index 45b34a52a292..7690d343c742 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -117,6 +117,10 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=&group_id=5470&atid - #117745 - UserString.py - Fix two typos in __imul__. +- #130306 - statcache.py - full of thread problems. + +- Made statcache.forget_dir more portable + What's New in Python 2.0? =========================