]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
- #130306 - statcache.py - full of thread problems.
authorMoshe Zadka <moshez@math.huji.ac.il>
Sat, 31 Mar 2001 13:46:34 +0000 (13:46 +0000)
committerMoshe Zadka <moshez@math.huji.ac.il>
Sat, 31 Mar 2001 13:46:34 +0000 (13:46 +0000)
- Made statcache.forget_dir more portable

Lib/statcache.py
Misc/NEWS

index b5147c233dc545952790a88e3f014d6427565c01..7eb87b96a96905da61c04c8e64532cc479bf1701 100644 (file)
@@ -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):
index 45b34a52a2921dfd37ec771c4d139befee135323..7690d343c742efc5e60c53ca86658634aa9cb50d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -117,6 +117,10 @@ http://sourceforge.net/tracker/index.php?func=detail&aid=<id>&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?
 =========================