# HG changeset patch # User Ludovic Chabant # Date 1428085371 25200 # Node ID aa6b7ff6a1933f53c41eaaf0486ad4957fafa4f2 # Parent 8511137d1b629c10c178c229ae58846aa2e5d23c internal: Use hashes for cache paths. This will prevent collisions (_e.g._ between `foo/bar` and `foo_bar`), and generating paths that are too long and exceed OS limits. diff -r 8511137d1b62 -r aa6b7ff6a193 piecrust/environment.py --- a/piecrust/environment.py Fri Apr 03 11:20:30 2015 -0700 +++ b/piecrust/environment.py Fri Apr 03 11:22:51 2015 -0700 @@ -2,6 +2,7 @@ import time import json import logging +import hashlib import threading import contextlib import collections @@ -15,7 +16,7 @@ def _make_fs_cache_key(key): - return re_fs_cache_key.sub('_', key) + return hashlib.md5(key.encode('utf8')).hexdigest() class MemCache(object): diff -r 8511137d1b62 -r aa6b7ff6a193 piecrust/page.py --- a/piecrust/page.py Fri Apr 03 11:20:30 2015 -0700 +++ b/piecrust/page.py Fri Apr 03 11:22:51 2015 -0700 @@ -251,8 +251,7 @@ def _do_load_page(app, path, path_mtime): # Check the cache first. cache = app.cache.getCache('pages') - rel_path = os.path.relpath(path, app.root_dir) - cache_path = "%s.json" % rel_path.replace('/', '_').strip('_') + cache_path = hashlib.md5(path.encode('utf8')).hexdigest() + '.json' page_time = path_mtime or os.path.getmtime(path) if cache.isValid(cache_path, page_time): cache_data = json.loads(cache.read(cache_path),