Add version number for item cache

This commit is contained in:
Unrud 2017-09-11 19:32:08 +02:00
parent d0891d17b9
commit 9ced675423

View File

@ -40,6 +40,7 @@ from contextlib import contextmanager
from hashlib import md5 from hashlib import md5
from importlib import import_module from importlib import import_module
from itertools import chain, groupby from itertools import chain, groupby
from math import log
from random import getrandbits from random import getrandbits
from tempfile import NamedTemporaryFile, TemporaryDirectory from tempfile import NamedTemporaryFile, TemporaryDirectory
@ -308,6 +309,11 @@ def path_to_filesystem(root, *paths):
return safe_path return safe_path
def left_encode_int(v):
length = int(log(v, 256)) + 1 if v != 0 else 1
return b"%c%s" % (length, v.to_bytes(length, 'little'))
class UnsafePathError(ValueError): class UnsafePathError(ValueError):
def __init__(self, path): def __init__(self, path):
message = "Can't translate name safely to filesystem: %r" % path message = "Can't translate name safely to filesystem: %r" % path
@ -726,6 +732,9 @@ class BaseCollection:
return True return True
ITEM_CACHE_VERSION = 1
class Collection(BaseCollection): class Collection(BaseCollection):
"""Collection stored in several files per calendar.""" """Collection stored in several files per calendar."""
@ -1247,6 +1256,7 @@ class Collection(BaseCollection):
def _item_cache_hash(self, raw_text): def _item_cache_hash(self, raw_text):
_hash = md5() _hash = md5()
_hash.update(left_encode_int(ITEM_CACHE_VERSION))
_hash.update(raw_text) _hash.update(raw_text)
return _hash.hexdigest() return _hash.hexdigest()