Include versions in item cache hash

This commit is contained in:
Unrud 2018-08-18 12:56:40 +02:00
parent f708a7b2b6
commit 5d969ff65c

View File

@ -40,10 +40,10 @@ 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
import pkg_resources
import vobject import vobject
from radicale import xmlutils from radicale import xmlutils
@ -90,6 +90,10 @@ elif os.name == "posix":
INTERNAL_TYPES = ("multifilesystem",) INTERNAL_TYPES = ("multifilesystem",)
DEPS = ("radicale", "vobject", "python-dateutil",)
ITEM_CACHE_TAG = (";".join(pkg_resources.get_distribution(pkg).version
for pkg in DEPS) + ";").encode()
def load(configuration): def load(configuration):
"""Load the storage manager chosen in configuration.""" """Load the storage manager chosen in configuration."""
@ -331,11 +335,6 @@ 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 bytes((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
@ -723,9 +722,6 @@ 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."""
@ -1277,7 +1273,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(ITEM_CACHE_TAG)
_hash.update(raw_text) _hash.update(raw_text)
return _hash.hexdigest() return _hash.hexdigest()