From d300949fe82235478526f135e444632cd8dba00e Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sun, 30 Nov 2014 13:49:11 +0100 Subject: [PATCH] Improve errorhandling in multifilesystem If the collection doesn't exist yet, OSError(2, 'No such file or directory') is raised. https://travis-ci.org/untitaker/vdirsyncer/jobs/42540595 --- radicale/storage/multifilesystem.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/radicale/storage/multifilesystem.py b/radicale/storage/multifilesystem.py index a3f7589..30f8c2d 100644 --- a/radicale/storage/multifilesystem.py +++ b/radicale/storage/multifilesystem.py @@ -29,6 +29,7 @@ import sys from . import filesystem from .. import ical +from .. import log class Collection(filesystem.Collection): @@ -69,14 +70,23 @@ class Collection(filesystem.Collection): ical.Timezone, ical.Event, ical.Todo, ical.Journal, ical.Card) items = set() try: - for filename in os.listdir(self._path): - with filesystem.open(os.path.join(self._path, filename)) as fd: - items.update(self._parse(fd.read(), components)) - except IOError: + filenames = os.listdir(self._path) + except (OSError, IOError) as e: + log.LOGGER.info('Error while reading collection %r: %r' + % (self._path, e)) return "" - else: - return ical.serialize( - self.tag, self.headers, sorted(items, key=lambda x: x.name)) + + for filename in filenames: + path = os.path.join(self._path, filename) + try: + with filesystem.open(path) as fd: + items.update(self._parse(fd.read(), components)) + except (OSError, IOError) as e: + log.LOGGER.warning('Error while reading item %r: %r' + % (path, e)) + + return ical.serialize( + self.tag, self.headers, sorted(items, key=lambda x: x.name)) @classmethod def is_node(cls, path):