[Python-checkins] CVS: python/dist/src/Lib statcache.py,1.7,1.7.4.1

Moshe Zadka moshez@users.sourceforge.net
Sat, 31 Mar 2001 05:46:36 -0800


Update of /cvsroot/python/python/dist/src/Lib
In directory usw-pr-cvs1:/tmp/cvs-serv18533/Lib

Modified Files:
      Tag: release20-maint
	statcache.py 
Log Message:
- #130306 - statcache.py - full of thread problems.

- Made statcache.forget_dir more portable


Index: statcache.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/statcache.py,v
retrieving revision 1.7
retrieving revision 1.7.4.1
diff -C2 -r1.7 -r1.7.4.1
*** statcache.py	2000/02/04 15:39:30	1.7
--- statcache.py	2001/03/31 13:46:33	1.7.4.1
***************
*** 15,20 ****
  def stat(path):
  	"""Stat a file, possibly out of the cache."""
! 	if cache.has_key(path):
! 		return cache[path]
  	cache[path] = ret = os.stat(path)
  	return ret
--- 15,21 ----
  def stat(path):
  	"""Stat a file, possibly out of the cache."""
! 	ret = cache.get(path, None)
! 	if ret is not None:
! 		return ret
  	cache[path] = ret = os.stat(path)
  	return ret
***************
*** 23,34 ****
  def reset():
  	"""Reset the cache completely."""
! 	global cache
! 	cache = {}
  
  
  def forget(path):
  	"""Remove a given item from the cache, if it exists."""
! 	if cache.has_key(path):
  		del cache[path]
  
  
--- 24,36 ----
  def reset():
  	"""Reset the cache completely."""
! 	cache.clear()
  
  
  def forget(path):
  	"""Remove a given item from the cache, if it exists."""
! 	try:
  		del cache[path]
+ 	except KeyError:
+ 		pass
  
  
***************
*** 38,42 ****
  	for path in cache.keys():
  		if path[:n] == prefix:
! 			del cache[path]
  
  
--- 40,44 ----
  	for path in cache.keys():
  		if path[:n] == prefix:
! 			forget(path)
  
  
***************
*** 44,60 ****
  	"""Forget about a directory and all entries in it, but not about
  	entries in subdirectories."""
! 	if prefix[-1:] == '/' and prefix <> '/':
! 		prefix = prefix[:-1]
  	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]
! 
  
  def forget_except_prefix(prefix):
--- 46,55 ----
  	"""Forget about a directory and all entries in it, but not about
  	entries in subdirectories."""
! 	import os.path
! 	prefix = os.path.dirname(os.path.join(prefix, "xxx"))
  	forget(prefix)
  	for path in cache.keys():
! 	if path.startswith(prefix) and os.path.dirname(path) == prefix:
! 		forget(path)
  
  def forget_except_prefix(prefix):
***************
*** 64,68 ****
  	for path in cache.keys():
  		if path[:n] <> prefix:
! 			del cache[path]
  
  
--- 59,63 ----
  	for path in cache.keys():
  		if path[:n] <> prefix:
! 			forget(path)