From cd97aab72caaf5a273e04231c27b9956efc50263 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 17 Sep 2016 12:52:42 +0200 Subject: [PATCH 1/4] try/catch of objects avoiding not serving any object in case an object has no valid contents also log duration of how many objects are read per folder --- radicale/storage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/radicale/storage.py b/radicale/storage.py index a67fbf9..2d60c58 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -34,6 +34,7 @@ import stat import subprocess import threading import time +import datetime from contextlib import contextmanager from hashlib import md5 from importlib import import_module @@ -699,6 +700,7 @@ class Collection(BaseCollection): if not os.path.exists(self._filesystem_path): return None items = [] + time_begin = datetime.datetime.now() for href in os.listdir(self._filesystem_path): if not is_safe_filesystem_path_component(href): self.logger.debug("Skipping component: %s", href) @@ -707,7 +709,12 @@ class Collection(BaseCollection): if os.path.isfile(path): self.logger.debug("Read object: %s", path) with open(path, encoding=self.encoding, newline="") as fd: - items.append(vobject.readOne(fd.read())) + try: + items.append(vobject.readOne(fd.read())) + except: + self.logger.error("Object broken (skip): %s", path) + time_end = datetime.datetime.now() + self.logger.info("Collection read %d items in %s sec from %s", len(items),(time_end - time_begin).total_seconds(), self._filesystem_path) if self.get_meta("tag") == "VCALENDAR": collection = vobject.iCalendar() for item in items: From a57fcad270dd9938c6eda6c4b48f06d78fd19bb3 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 17 Sep 2016 13:56:27 +0200 Subject: [PATCH 2/4] catch 2nd case for broken object --- radicale/storage.py | 9 +++++++-- radicale/xmlutils.py | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index 2d60c58..9ac01fe 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -635,7 +635,12 @@ class Collection(BaseCollection): last_modified = time.strftime( "%a, %d %b %Y %H:%M:%S GMT", time.gmtime(os.path.getmtime(path))) - return Item(self, vobject.readOne(text), href, last_modified) + try: + item = Item(self, vobject.readOne(text), href, last_modified) + except: + self.logger.error("Object broken (skip 'get'): %s", path) + return None; + return item; def has(self, href): return self.get(href) is not None @@ -712,7 +717,7 @@ class Collection(BaseCollection): try: items.append(vobject.readOne(fd.read())) except: - self.logger.error("Object broken (skip): %s", path) + self.logger.error("Object broken (skip 'list'): %s", path) time_end = datetime.datetime.now() self.logger.info("Collection read %d items in %s sec from %s", len(items),(time_end - time_begin).total_seconds(), self._filesystem_path) if self.get_meta("tag") == "VCALENDAR": diff --git a/radicale/xmlutils.py b/radicale/xmlutils.py index a75a441..1c2a428 100644 --- a/radicale/xmlutils.py +++ b/radicale/xmlutils.py @@ -796,6 +796,8 @@ def report(path, xml_request, collection): items = collection.pre_filtered_list(filters) for item in items: + if not item: + continue if filters: match = ( _comp_match if collection.get_meta("tag") == "VCALENDAR" From e6ba31937adf2a3b3fdce9f6e51deb16d6de33f4 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 17 Sep 2016 15:11:02 +0200 Subject: [PATCH 3/4] 3rd catch --- radicale/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/radicale/__init__.py b/radicale/__init__.py index c5266e8..49cecfb 100644 --- a/radicale/__init__.py +++ b/radicale/__init__.py @@ -244,6 +244,8 @@ class Application: read_allowed_items = [] write_allowed_items = [] for item in items: + if not item: + continue if isinstance(item, self.Collection): path = item.path else: From 18181374e1a188888d6ee7251861d887f7aea0b0 Mon Sep 17 00:00:00 2001 From: Peter Bieringer Date: Sat, 17 Sep 2016 16:29:40 +0200 Subject: [PATCH 4/4] log exception for broken items --- radicale/storage.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radicale/storage.py b/radicale/storage.py index 9ac01fe..b42b862 100644 --- a/radicale/storage.py +++ b/radicale/storage.py @@ -638,7 +638,7 @@ class Collection(BaseCollection): try: item = Item(self, vobject.readOne(text), href, last_modified) except: - self.logger.error("Object broken (skip 'get'): %s", path) + self.logger.exception("Object broken (skip 'get'): %s", path) return None; return item; @@ -717,7 +717,7 @@ class Collection(BaseCollection): try: items.append(vobject.readOne(fd.read())) except: - self.logger.error("Object broken (skip 'list'): %s", path) + self.logger.exception("Object broken (skip 'list'): %s", path) time_end = datetime.datetime.now() self.logger.info("Collection read %d items in %s sec from %s", len(items),(time_end - time_begin).total_seconds(), self._filesystem_path) if self.get_meta("tag") == "VCALENDAR":