From 0060130c3b16d06f4f876857b063a6c88c323e37 Mon Sep 17 00:00:00 2001 From: Unrud Date: Thu, 11 Aug 2016 05:05:10 +0200 Subject: [PATCH] Remove etags from raw data Remove all etags that are directly calculated from data that's read from files. 1. They are not used anywhere (luckily). 2. Etags that are send to clients are calculated from the output of vobject's serialize method. If files are edited externally and vobject normalizes them (like wrapping long lines or replacing all line endings by \r\n), the etags that are sent to the client and the etags that are calculated from raw data will never match. If a new version of vobject is released and the formatting changes slightly, the checks will also always fail. --- radicale/storage.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index 594dc06..3ef62d1 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -306,7 +306,7 @@ class BaseCollection: the filters and this implementation. This returns all event by default """ - return [self.get(href) for href, _ in self.list()] + return [self.get(href) for href in self.list()] def has(self, href): """Check if an item exists by its href. @@ -321,17 +321,17 @@ class BaseCollection: """Upload a new item.""" raise NotImplementedError - def update(self, href, vobject_item, etag=None): + def update(self, href, vobject_item): """Update an item. Functionally similar to ``delete`` plus ``upload``, but might bring performance benefits on some storages when used cleverly. """ - self.delete(href, etag) + self.delete(href) self.upload(href, vobject_item) - def delete(self, href=None, etag=None): + def delete(self, href=None): """Delete an item. When ``href`` is ``None``, delete the collection. @@ -500,7 +500,7 @@ class Collection(BaseCollection): return for item in collection.list(): - yield collection.get(item[0]) + yield collection.get(item) for href in os.listdir(filesystem_path): if not is_safe_filesystem_path_component(href): @@ -593,8 +593,7 @@ class Collection(BaseCollection): continue path = os.path.join(self._filesystem_path, href) if os.path.isfile(path): - with open(path, encoding=self.encoding) as fd: - yield href, get_etag(fd.read()) + yield href def get(self, href): if not href: @@ -628,22 +627,18 @@ class Collection(BaseCollection): fd.write(item.serialize()) return item - def update(self, href, vobject_item, etag=None): + def update(self, href, vobject_item): if not is_safe_filesystem_path_component(href): raise UnsafePathError(href) path = path_to_filesystem(self._filesystem_path, href) if not os.path.isfile(path): raise ComponentNotFoundError(href) - with open(path, encoding=self.encoding) as fd: - text = fd.read() - if etag and etag != get_etag(text): - raise EtagMismatchError(etag, get_etag(text)) item = Item(self, vobject_item, href) with self._atomic_write(path) as fd: fd.write(item.serialize()) return item - def delete(self, href=None, etag=None): + def delete(self, href=None): if href is None: # Delete the collection if os.path.isdir(self._filesystem_path): @@ -665,10 +660,6 @@ class Collection(BaseCollection): path = path_to_filesystem(self._filesystem_path, href) if not os.path.isfile(path): raise ComponentNotFoundError(href) - with open(path, encoding=self.encoding) as fd: - text = fd.read() - if etag and etag != get_etag(text): - raise EtagMismatchError(etag, get_etag(text)) os.remove(path) self._sync_directory(os.path.dirname(path))