3 # Maintain a cache of file stats.
4 # There are functions to reset the cache or to selectively remove items.
10 # Keys are pathnames, values are `os.stat' outcomes.
15 # Stat a file, possibly out of the cache.
18 if cache
.has_key(path
):
20 cache
[path
] = ret
= os
.stat(path
)
24 # Reset the cache completely.
31 # Remove a given item from the cache, if it exists.
34 if cache
.has_key(path
):
38 # Remove all pathnames with a given prefix.
40 def forget_prefix(prefix
):
42 for path
in cache
.keys():
43 if path
[:n
] == prefix
:
47 # Forget about a directory and all entries in it, but not about
48 # entries in subdirectories.
50 def forget_dir(prefix
):
51 if prefix
[-1:] == '/' and prefix
<> '/':
54 if prefix
[-1:] <> '/':
57 for path
in cache
.keys():
58 if path
[:n
] == prefix
:
60 if rest
[-1:] == '/': rest
= rest
[:-1]
65 # Remove all pathnames except with a given prefix.
66 # Normally used with prefix = '/' after a chdir().
68 def forget_except_prefix(prefix
):
70 for path
in cache
.keys():
71 if path
[:n
] <> prefix
:
75 # Check for directory.
82 return S_ISDIR(st
[ST_MODE
])