[kupfer] core.sources: Take source name into account for Cache file name



commit 4fd603f62ec967f773d64c52344fbdcb16a1769e
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Jan 13 00:02:01 2010 +0100

    core.sources: Take source name into account for Cache file name
    
    We change the cache file name (again) so that the name of the source
    is part of the generation. Then sources are automatically changed when
    we switch locale.
    
    We also bump the cache version number to 4!
    
    This means after this change, **Kupfer will erase all** old cache
    files with version number 3 in their name, to clean up.

 kupfer/core/sources.py |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/core/sources.py b/kupfer/core/sources.py
index 243791b..785df85 100644
--- a/kupfer/core/sources.py
+++ b/kupfer/core/sources.py
@@ -81,7 +81,7 @@ class SourcePickler (pretty.OutputMixin):
 	"""
 	Takes care of pickling and unpickling Kupfer Sources.
 	"""
-	pickle_version = 3
+	pickle_version = 4
 	name_template = "k%s-v%d.pickle.gz"
 
 	def __init__(self):
@@ -112,7 +112,10 @@ class SourcePickler (pretty.OutputMixin):
 
 	def get_filename(self, source):
 		"""Return cache filename for @source"""
-		bytes = hashlib.md5(repr(source)).digest()
+		# make sure we take the source name into account
+		# so that we get a "break" when locale changes
+		source_id = "%s%s%s" % (repr(source), str(source), source.version)
+		bytes = hashlib.md5(source_id).digest()
 		hashstr = bytes.encode("base64").rstrip("\n=").replace("/", "-")
 		filename = self.name_template % (hashstr, self.pickle_version)
 		return os.path.join(config.get_cache_home(), filename)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]